diff --git a/src/Utilities/Miscellaneous.php b/src/Utilities/Miscellaneous.php index 39681ed..3038711 100644 --- a/src/Utilities/Miscellaneous.php +++ b/src/Utilities/Miscellaneous.php @@ -563,21 +563,22 @@ class Miscellaneous * @param string $suffix (optional) The suffix to add at the end of string * @return string */ - public static function substringToWord($text, $maxLength, $suffix = '...') + public static function substringToWord(string $text, int $maxLength, string $suffix = '...'): string { $effect = $text; + $encoding = 'utf-8'; - $textLength = mb_strlen($text, 'utf-8'); - $suffixLength = mb_strlen($suffix, 'utf-8'); + $textLength = mb_strlen($text, $encoding); + $suffixLength = mb_strlen($suffix, $encoding); $maxLength -= $suffixLength; if ($textLength > $maxLength) { - $effect = mb_substr($text, 0, $maxLength, 'utf-8'); - $lastSpacePosition = mb_strrpos($effect, ' ', 0, 'utf-8'); + $effect = mb_substr($text, 0, $maxLength, $encoding); + $lastSpacePosition = mb_strrpos($effect, ' ', 0, $encoding); if (false !== $lastSpacePosition) { - $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8'); + $effect = mb_substr($effect, 0, $lastSpacePosition, $encoding); } $effect .= $suffix; diff --git a/src/Utilities/Reflection.php b/src/Utilities/Reflection.php index e641338..90ed38a 100644 --- a/src/Utilities/Reflection.php +++ b/src/Utilities/Reflection.php @@ -502,7 +502,7 @@ class Reflection * * @param array|object|string $class An array of objects, namespaces, object or namespace * @param string $property Name of the property - * @param int $filter (optional) Filter of properties. Uses \ReflectionProperty class constants. + * @param int|null $filter (optional) Filter of properties. Uses \ReflectionProperty class constants. * By default all properties are allowed / processed. * @return null|ReflectionProperty */ @@ -512,7 +512,6 @@ class Reflection $properties = self::getProperties($className, $filter); if (!empty($properties)) { - /** @var ReflectionProperty $reflectionProperty */ foreach ($properties as $reflectionProperty) { if ($reflectionProperty->getName() === $property) { return $reflectionProperty; diff --git a/tests/Utilities/ReflectionTest.php b/tests/Utilities/ReflectionTest.php index 1f9ff30..c7adbbe 100644 --- a/tests/Utilities/ReflectionTest.php +++ b/tests/Utilities/ReflectionTest.php @@ -222,7 +222,7 @@ class ReflectionTest extends BaseTestCase public function testUsesTraitInvalidTrait($trait): void { $this->expectException(CannotResolveClassNameException::class); - self::assertNull(Reflection::usesTrait(DateTime::class, $trait)); + Reflection::usesTrait(DateTime::class, $trait); } public function testUsesTraitExistingClass(): void