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

The-oGlow / ezkoding / 40125643554

24 Oct 2026 07:30PM UTC coverage: 80.655% (-3.8%) from 84.414%
40125643554

push

github

web-flow
Merge pull request #16 from The-oGlow/develop

Develop

11 of 13 new or added lines in 8 files covered. (84.62%)

13 existing lines in 3 files now uncovered.

517 of 641 relevant lines covered (80.66%)

7.73 hits per line

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

87.5
/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
use TypeError;
17

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

48
        return $result;
4 ✔
49
    }
50

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

63
        /**
64
         * Trait does not know where it is used.
65
         *
66
         * @psalm-suppress UndefinedThisPropertyFetch
67
         * @phpstan-ignore isset.property,property.notFound
68
         */
69
        if (isset($this->o2t)) {
4 ✔
70
            try {
71
                $clazzName = get_class($this->o2t);
3 ✔
72
                $result = $this->callMethodByReflection($clazzName, $methodName, $this->o2t, $parameters);
3 ✔
NEW
73
            } catch (TypeError $tException) {
×
74
                // ignore
75
            }
76
        }
77

78
        return $result;
4 ✔
79
    }
80
}
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