• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

selamiphp / stdlib / 73

pending completion
73

push

travis-ci-com

mkorkmaz
fix: cs for php8.0

5 of 5 new or added lines in 4 files covered. (100.0%)

104 of 123 relevant lines covered (84.55%)

27.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
/src/Resolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Selami\Stdlib;
6

7
use ReflectionException;
8
use ReflectionMethod;
9
use ReflectionParameter;
10
use Selami\Stdlib\Exception\ClassOrMethodCouldNotBeFound;
11

12
use function assert;
13
use function class_exists;
14
use function is_array;
15
use function method_exists;
16
use function sprintf;
17

18
class Resolver
19
{
20
    public const ARRAY    = 'array';
21
    public const CALLABLE = 'callable';
22
    public const BOOLEAN  = 'boolean';
23
    public const FLOAT    = 'float';
24
    public const INTEGER  = 'int';
25
    public const STRING   = 'string';
26
    public const ITERABLE = 'iterable';
27

28
    public static function getParameterHints(string $className, string $methodName): array
29
    {
30
        self::checkClassName($className);
21✔
31
        self::checkMethodName($className, $methodName);
18✔
32
        try {
33
            $method = new ReflectionMethod($className, $methodName);
15✔
34
        } catch (ReflectionException) {
×
35
            throw new ClassOrMethodCouldNotBeFound(
×
36
                sprintf('%s::%s coulnd not be found.', $className, $methodName)
×
37
            );
×
38
        }
39

40
        $parameters = $method->getParameters();
15✔
41
        assert(is_array($parameters));
15✔
42
        $parameterHints = [];
15✔
43
        foreach ($parameters as $param) {
15✔
44
            $parameter                          = self::getParamType($param);
6✔
45
            $parameterHints[$parameter['name']] = $parameter['type'];
6✔
46
        }
47

48
        return $parameterHints;
15✔
49
    }
50

51
    private static function checkClassName(string $className): void
52
    {
53
        if (! class_exists($className)) {
21✔
54
            throw new ClassOrMethodCouldNotBeFound(
3✔
55
                sprintf('%s class does not exist!', $className)
3✔
56
            );
3✔
57
        }
58
    }
59

60
    private static function checkMethodName(string $className, string $methodName): void
61
    {
62
        if (! method_exists($className, $methodName)) {
18✔
63
            throw new ClassOrMethodCouldNotBeFound(
3✔
64
                sprintf('%s does not have method named %s!', $className, $methodName)
3✔
65
            );
3✔
66
        }
67
    }
68

69
    private static function getParamType(ReflectionParameter $parameter): array
70
    {
71
        $type = $parameter->getType();
6✔
72
        if ($type->isBuiltin()) {
6✔
73
            return ['name' => $parameter->name, 'type' => $type->getName()];
3✔
74
        }
75

76
        try {
77
            return ['name' => $parameter->name, 'type' => $type->getName()];
6✔
78
        } catch (ReflectionException $e) {
×
79
            throw new ClassOrMethodCouldNotBeFound($e->getMessage());
×
80
        }
81
    }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc