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

The-oGlow / ezkoding / 37125812891

03 Oct 2026 01:19PM UTC coverage: 85.037% (-0.5%) from 85.553%
37125812891

push

github

ollily
update / tested

5 of 6 new or added lines in 1 file covered. (83.33%)

4 existing lines in 1 file now uncovered.

682 of 802 relevant lines covered (85.04%)

7.42 hits per line

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

93.75
/src/Tools/Reflection/UnavailableMethodsTrait.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of ezkoding
7
 *
8
 * (c) 2025 Oliver Glowa, coding.glowa.com
9
 *
10
 * This source file is subject to the Apache-2.0 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace ollily\Tools\Reflection;
15

16
/**
17
 * Provides access on non public methods in a clazz.
18
 *
19
 * @author ollily
20
 */
21
trait UnavailableMethodsTrait
22
{
23
    /**
24
     * Calls hidden method (private, protected, package) without parameters by reflection.
25
     *
26
     * @param mixed  $clazzName  The name of the clazz
27
     * @param string $methodName The name of the method to call
28
     * @param mixed  $instance   The current instance to call on
29
     * @param array<mixed> $parameters = The parameters for the method to call (Default: [])
30
     *
31
     * @return mixed The result of the called method
32
     */
33
    protected function callMethodByReflection(mixed $clazzName, string $methodName, mixed $instance, array $parameters=[]): mixed
4 ✔
34
    {
35
        $result = null;
4 ✔
36
        if (!empty($clazzName)) {
4 ✔
37
            $refObject = new \ReflectionMethod($clazzName, $methodName);
4 ✔
38
            $refObject->setAccessible(true); // NOSONAR: php:S3011
4 ✔
39
            if (count($parameters) > 0) {
4 ✔
NEW
40
                $result = $refObject->invokeArgs($instance, $parameters);
×
41
            } else {
42
                $result = $refObject->invoke($instance);
4 ✔
43
            }
44
        }
45

46
        return $result;
4 ✔
47
    }
48

49
    /**
50
     * Calls a hidden method on an instance of the test object (o2t).
51
     *
52
     * @param string $methodName The name of the method to call
53
     * @param array<mixed> $parameters = The parameters for the method to call (Default: [])
54
     *
55
     * @return mixed The result of the called method
56
     */
57
    protected function callMethodOnO2t(string $methodName, array $parameters = []): mixed
4 ✔
58
    {
59
        $result = null;
4 ✔
60

61
        /**
62
         * @psalm-suppress RedundantPropertyInitializationCheck,UndefinedThisPropertyFetch
63
         * @phpstan-ignore isset.property,property.notFound
64
         */
65
        if (isset($this->o2t)) {
4 ✔
66
            $clazzName = get_class($this->o2t);
3 ✔
67
            /** @psalm-suppress RedundantCondition */
68
            if (!empty($clazzName)) {
3 ✔
69
                $result = $this->callMethodByReflection($clazzName, $methodName, $this->o2t, $parameters);
3 ✔
70
            }
71
        }
72

73
        return $result;
4 ✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc