Completed
Pull Request — master (#565)
by
unknown
03:09
created

Mock::mockery_getMethods()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 10
cp 0
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
crap 12
1
<?php
2
/**
3
 * Mockery
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://github.com/padraic/mockery/blob/master/LICENSE
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Mockery
16
 * @package    Mockery
17
 * @copyright  Copyright (c) 2010-2014 Pádraic Brady (http://blog.astrumfutura.com)
18
 * @license    http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19
 */
20
21
namespace Mockery;
22
23
use Mockery\MockInterface;
24
25
class Mock implements MockInterface
26
{
27
    /**
28
     * Stores an array of all expectation directors for this mock
29
     *
30
     * @var array
31
     */
32
    protected $_mockery_expectations = array();
33
34
    /**
35
     * Stores an inital number of expectations that can be manipulated
36
     * while using the getter method.
37
     *
38
     * @var int
39
     */
40
    protected $_mockery_expectations_count = 0;
41
42
    /**
43
     * Flag to indicate whether we can ignore method calls missing from our
44
     * expectations
45
     *
46
     * @var bool
47
     */
48
    protected $_mockery_ignoreMissing = false;
49
50
    /**
51
     * Flag to indicate whether we can defer method calls missing from our
52
     * expectations
53
     *
54
     * @var bool
55
     */
56
    protected $_mockery_deferMissing = false;
57
58
    /**
59
     * Flag to indicate whether this mock was verified
60
     *
61
     * @var bool
62
     */
63
    protected $_mockery_verified = false;
64
65
    /**
66
     * Given name of the mock
67
     *
68
     * @var string
69
     */
70
    protected $_mockery_name = null;
71
72
    /**
73
     * Order number of allocation
74
     *
75
     * @var int
76
     */
77
    protected $_mockery_allocatedOrder = 0;
78
79
    /**
80
     * Current ordered number
81
     *
82
     * @var int
83
     */
84
    protected $_mockery_currentOrder = 0;
85
86
    /**
87
     * Ordered groups
88
     *
89
     * @var array
90
     */
91
    protected $_mockery_groups = array();
92
93
    /**
94
     * Mock container containing this mock object
95
     *
96
     * @var \Mockery\Container
97
     */
98
    protected $_mockery_container = null;
99
100
    /**
101
     * Instance of a core object on which methods are called in the event
102
     * it has been set, and an expectation for one of the object's methods
103
     * does not exist. This implements a simple partial mock proxy system.
104
     *
105
     * @var object
106
     */
107
    protected $_mockery_partial = null;
108
109
    /**
110
     * Flag to indicate we should ignore all expectations temporarily. Used
111
     * mainly to prevent expectation matching when in the middle of a mock
112
     * object recording session.
113
     *
114
     * @var bool
115
     */
116
    protected $_mockery_disableExpectationMatching = false;
117
118
    /**
119
     * Stores all stubbed public methods separate from any on-object public
120
     * properties that may exist.
121
     *
122
     * @var array
123
     */
124
    protected $_mockery_mockableProperties = array();
125
126
    /**
127
     * @var array
128
     */
129
    protected $_mockery_mockableMethods = array();
130
131
    /**
132
     * Just a local cache for this mock's target's methods
133
     *
134
     * @var ReflectionMethod[]
135
     */
136
    protected static $_mockery_methods;
137
138
    protected $_mockery_allowMockingProtectedMethods = false;
139
140
    protected $_mockery_receivedMethodCalls;
141
142
    /**
143
     * If shouldIgnoreMissing is called, this value will be returned on all calls to missing methods
144
     * @var mixed
145
     */
146
    protected $_mockery_defaultReturnValue = null;
147
148
    /**
149
     * We want to avoid constructors since class is copied to Generator.php
150
     * for inclusion on extending class definitions.
151
     *
152
     * @param \Mockery\Container $container
153
     * @param object $partialObject
154
     * @return void
155
     */
156
    public function mockery_init(\Mockery\Container $container = null, $partialObject = null)
157
    {
158
        if (is_null($container)) {
159
            $container = new \Mockery\Container;
160
        }
161
        $this->_mockery_container = $container;
162
        if (!is_null($partialObject)) {
163
            $this->_mockery_partial = $partialObject;
164
        }
165
166
        if (!\Mockery::getConfiguration()->mockingNonExistentMethodsAllowed()) {
167
            foreach ($this->mockery_getMethods() as $method) {
168
                if ($method->isPublic() && !$method->isStatic()) {
169
                    $this->_mockery_mockableMethods[] = $method->getName();
170
                }
171
            }
172
        }
173
    }
174
175
    /**
176
     * Set expected method calls
177
     *
178
     * @param string $methodName,... one or many methods that are expected to be called in this mock
179
     * @return \Mockery\Expectation
180
     */
181
    public function shouldReceive($methodName)
182
    {
183
        if (func_num_args() < 1) {
184
            throw new \InvalidArgumentException("At least one method name is required");
185
        }
186
187
        foreach (func_get_args() as $method) {
188
            if ("" == $method) {
189
                throw new \InvalidArgumentException("Received empty method name");
190
            }
191
        }
192
193
        /** @var array $nonPublicMethods */
194
        $nonPublicMethods = $this->getNonPublicMethods();
195
196
        $self = $this;
197
        $allowMockingProtectedMethods = $this->_mockery_allowMockingProtectedMethods;
198
199
        $lastExpectation = \Mockery::parseShouldReturnArgs(
200
            $this, func_get_args(), function ($method) use ($self, $nonPublicMethods, $allowMockingProtectedMethods) {
201
                $rm = $self->mockery_getMethod($method);
202
                if ($rm) {
203
                    if ($rm->isPrivate()) {
204
                        throw new \InvalidArgumentException("$method() cannot be mocked as it is a private method");
205
                    }
206
                    if (!$allowMockingProtectedMethods && $rm->isProtected()) {
207
                        throw new \InvalidArgumentException("$method() cannot be mocked as it is a protected method and mocking protected methods is not enabled for the currently used mock object.");
208
                    }
209
                }
210
211
                $director = $self->mockery_getExpectationsFor($method);
212
                if (!$director) {
213
                    $director = new \Mockery\ExpectationDirector($method, $self);
214
                    $self->mockery_setExpectationsFor($method, $director);
215
                }
216
                $expectation = new \Mockery\Expectation($self, $method);
217
                $director->addExpectation($expectation);
218
                return $expectation;
219
            }
220
        );
221
        return $lastExpectation;
222
    }
223
224
    /**
225
     * Shortcut method for setting an expectation that a method should not be called.
226
     *
227
     * @param string $methodName,... one or many methods that are expected not to be called in this mock
228
     * @return \Mockery\Expectation
229
     */
230
    public function shouldNotReceive($methodName)
231
    {
232
        $expectation = call_user_func_array(array($this, 'shouldReceive'), func_get_args());
233
        $expectation->never();
234
        return $expectation;
235
    }
236
237
    /**
238
     * Allows additional methods to be mocked that do not explicitly exist on mocked class
239
     * @param String $method name of the method to be mocked
240
     * @return Mock
241
     */
242
    public function shouldAllowMockingMethod($method)
243
    {
244
        $this->_mockery_mockableMethods[] = $method;
245
        return $this;
246
    }
247
248
    /**
249
     * Set mock to ignore unexpected methods and return Undefined class
250
     * @param mixed $returnValue the default return value for calls to missing functions on this mock
251
     * @return Mock
252
     */
253
    public function shouldIgnoreMissing($returnValue = null)
254
    {
255
        $this->_mockery_ignoreMissing = true;
256
        $this->_mockery_defaultReturnValue = $returnValue;
257
        return $this;
258
    }
259
260
    public function asUndefined()
261
    {
262
        $this->_mockery_ignoreMissing = true;
263
        $this->_mockery_defaultReturnValue = new \Mockery\Undefined;
264
        return $this;
265
    }
266
267
    /**
268
     * @return Mock
269
     */
270
    public function shouldAllowMockingProtectedMethods()
271
    {
272
        $this->_mockery_allowMockingProtectedMethods = true;
273
        return $this;
274
    }
275
276
277
    /**
278
     * Set mock to defer unexpected methods to it's parent
279
     *
280
     * This is particularly useless for this class, as it doesn't have a parent,
281
     * but included for completeness
282
     *
283
     * @return Mock
284
     */
285
    public function shouldDeferMissing()
286
    {
287
        $this->_mockery_deferMissing = true;
288
        return $this;
289
    }
290
291
    /**
292
     * Create an obviously worded alias to shouldDeferMissing()
293
     *
294
     * @return Mock
295
     */
296
    public function makePartial()
297
    {
298
        return $this->shouldDeferMissing();
299
    }
300
301
    /**
302
     * Accepts a closure which is executed with an object recorder which proxies
303
     * to the partial source object. The intent being to record the
304
     * interactions of a concrete object as a set of expectations on the
305
     * current mock object. The partial may then be passed to a second process
306
     * to see if it fulfils the same (or exact same) contract as the original.
307
     *
308
     * @param Closure $closure
309
     */
310
    public function shouldExpect(\Closure $closure)
311
    {
312
        $recorder = new \Mockery\Recorder($this, $this->_mockery_partial);
313
        $this->_mockery_disableExpectationMatching = true;
314
        $closure($recorder);
315
        $this->_mockery_disableExpectationMatching = false;
316
        return $this;
317
    }
318
319
    /**
320
     * In the event shouldReceive() accepting one or more methods/returns,
321
     * this method will switch them from normal expectations to default
322
     * expectations
323
     *
324
     * @return self
325
     */
326
    public function byDefault()
327
    {
328
        foreach ($this->_mockery_expectations as $director) {
329
            $exps = $director->getExpectations();
330
            foreach ($exps as $exp) {
331
                $exp->byDefault();
332
            }
333
        }
334
        return $this;
335
    }
336
337
    /**
338
     * Capture calls to this mock
339
     */
340
    public function __call($method, array $args)
341
    {
342
        return $this->_mockery_handleMethodCall($method, $args);
343
    }
344
345
    public static function __callStatic($method, array $args)
346
    {
347
        return self::_mockery_handleStaticMethodCall($method, $args);
348
    }
349
350
    /**
351
     * Forward calls to this magic method to the __call method
352
     */
353
    public function __toString()
354
    {
355
        return $this->__call('__toString', array());
356
    }
357
358
    /**public function __set($name, $value)
359
    {
360
        $this->_mockery_mockableProperties[$name] = $value;
361
        return $this;
362
    }
363
364
    public function __get($name)
365
    {
366
        if (isset($this->_mockery_mockableProperties[$name])) {
367
            return $this->_mockery_mockableProperties[$name];
368
        } elseif(isset($this->{$name})) {
369
            return $this->{$name};
370
        }
371
        throw new \InvalidArgumentException (
372
            'Property ' . __CLASS__ . '::' . $name . ' does not exist on this mock object'
373
        );
374
    }**/
375
376
    /**
377
     * Iterate across all expectation directors and validate each
378
     *
379
     * @throws \Mockery\CountValidator\Exception
380
     * @return void
381
     */
382
    public function mockery_verify()
383
    {
384
        if ($this->_mockery_verified) {
385
            return true;
386
        }
387
        if (isset($this->_mockery_ignoreVerification)
388
            && $this->_mockery_ignoreVerification == true) {
389
            return true;
390
        }
391
        $this->_mockery_verified = true;
392
        foreach ($this->_mockery_expectations as $director) {
393
            $director->verify();
394
        }
395
    }
396
397
    /**
398
     * Tear down tasks for this mock
399
     *
400
     * @return void
401
     */
402
    public function mockery_teardown()
403
    {
404
    }
405
406
    /**
407
     * Fetch the next available allocation order number
408
     *
409
     * @return int
410
     */
411
    public function mockery_allocateOrder()
412
    {
413
        $this->_mockery_allocatedOrder += 1;
414
        return $this->_mockery_allocatedOrder;
415
    }
416
417
    /**
418
     * Set ordering for a group
419
     *
420
     * @param mixed $group
421
     * @param int $order
422
     */
423
    public function mockery_setGroup($group, $order)
424
    {
425
        $this->_mockery_groups[$group] = $order;
426
    }
427
428
    /**
429
     * Fetch array of ordered groups
430
     *
431
     * @return array
432
     */
433
    public function mockery_getGroups()
434
    {
435
        return $this->_mockery_groups;
436
    }
437
438
    /**
439
     * Set current ordered number
440
     *
441
     * @param int $order
442
     */
443
    public function mockery_setCurrentOrder($order)
444
    {
445
        $this->_mockery_currentOrder = $order;
446
        return $this->_mockery_currentOrder;
447
    }
448
449
    /**
450
     * Get current ordered number
451
     *
452
     * @return int
453
     */
454
    public function mockery_getCurrentOrder()
455
    {
456
        return $this->_mockery_currentOrder;
457
    }
458
459
    /**
460
     * Validate the current mock's ordering
461
     *
462
     * @param string $method
463
     * @param int $order
464
     * @throws \Mockery\Exception
465
     * @return void
466
     */
467
    public function mockery_validateOrder($method, $order)
468
    {
469
        if ($order < $this->_mockery_currentOrder) {
470
            $exception = new \Mockery\Exception\InvalidOrderException(
471
                'Method ' . __CLASS__ . '::' . $method . '()'
472
                . ' called out of order: expected order '
473
                . $order . ', was ' . $this->_mockery_currentOrder
474
            );
475
            $exception->setMock($this)
476
                ->setMethodName($method)
477
                ->setExpectedOrder($order)
478
                ->setActualOrder($this->_mockery_currentOrder);
479
            throw $exception;
480
        }
481
        $this->mockery_setCurrentOrder($order);
482
    }
483
484
    /**
485
     * Gets the count of expectations for this mock
486
     *
487
     * @return int
488
     */
489
    public function mockery_getExpectationCount()
490
    {
491
        $count = $this->_mockery_expectations_count;
492
        foreach ($this->_mockery_expectations as $director) {
493
            $count += $director->getExpectationCount();
494
        }
495
        return $count;
496
    }
497
498
    /**
499
     * Return the expectations director for the given method
500
     *
501
     * @var string $method
502
     * @return \Mockery\ExpectationDirector|null
503
     */
504
    public function mockery_setExpectationsFor($method, \Mockery\ExpectationDirector $director)
505
    {
506
        $this->_mockery_expectations[$method] = $director;
507
    }
508
509
    /**
510
     * Return the expectations director for the given method
511
     *
512
     * @var string $method
513
     * @return \Mockery\ExpectationDirector|null
514
     */
515
    public function mockery_getExpectationsFor($method)
516
    {
517
        if (isset($this->_mockery_expectations[$method])) {
518
            return $this->_mockery_expectations[$method];
519
        }
520
    }
521
522
    /**
523
     * Find an expectation matching the given method and arguments
524
     *
525
     * @var string $method
526
     * @var array $args
527
     * @return \Mockery\Expectation|null
528
     */
529
    public function mockery_findExpectation($method, array $args)
530
    {
531
        if (!isset($this->_mockery_expectations[$method])) {
532
            return null;
533
        }
534
        $director = $this->_mockery_expectations[$method];
535
536
        return $director->findExpectation($args);
537
    }
538
539
    /**
540
     * Return the container for this mock
541
     *
542
     * @return \Mockery\Container
543
     */
544
    public function mockery_getContainer()
545
    {
546
        return $this->_mockery_container;
547
    }
548
549
    /**
550
     * Return the name for this mock
551
     *
552
     * @return string
553
     */
554
    public function mockery_getName()
555
    {
556
        return __CLASS__;
557
    }
558
559
    /**
560
     * @return array
561
     */
562
    public function mockery_getMockableProperties()
563
    {
564
        return $this->_mockery_mockableProperties;
565
    }
566
567
    public function __isset($name)
568
    {
569
        if (false === stripos($name, '_mockery_') && method_exists(get_parent_class($this), '__isset')) {
570
            return parent::__isset($name);
571
        }
572
    }
573
574
    public function mockery_getExpectations()
575
    {
576
        return $this->_mockery_expectations;
577
    }
578
579
    /**
580
     * Calls a parent class method and returns the result. Used in a passthru
581
     * expectation where a real return value is required while still taking
582
     * advantage of expectation matching and call count verification.
583
     *
584
     * @param string $name
585
     * @param array $args
586
     * @return mixed
587
     */
588
    public function mockery_callSubjectMethod($name, array $args)
589
    {
590
        return call_user_func_array('parent::' . $name, $args);
591
    }
592
593
    /**
594
     * @return string[]
595
     */
596
    public function mockery_getMockableMethods()
597
    {
598
        return $this->_mockery_mockableMethods;
599
    }
600
601
    /**
602
     * @return bool
603
     */
604
    public function mockery_isAnonymous()
605
    {
606
        $rfc = new \ReflectionClass($this);
607
        return false === $rfc->getParentClass();
608
    }
609
610
    public function __wakeup()
611
    {
612
        /**
613
         * This does not add __wakeup method support. It's a blind method and any
614
         * expected __wakeup work will NOT be performed. It merely cuts off
615
         * annoying errors where a __wakeup exists but is not essential when
616
         * mocking
617
         */
618
    }
619
620
    public function __destruct()
621
    {
622
        /**
623
         * Overrides real class destructor in case if class was created without original constructor
624
         */
625
    }
626
627
    public function mockery_getMethod($name)
628
    {
629
        foreach ($this->mockery_getMethods() as $method) {
630
            if ($method->getName() == $name) {
631
                return $method;
632
            }
633
        }
634
635
        return null;
636
    }
637
638
    /**
639
     * @param string $name Method name.
640
     *
641
     * @return mixed Generated return value based on the declared return value of the named method.
642
     */
643
    public function mockery_returnValueForMethod($name)
644
    {
645
        if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) {
646
            return;
647
        }
648
649
        $rm = $this->mockery_getMethod($name);
650
        if (!$rm || !$rm->hasReturnType()) {
651
            return;
652
        }
653
654
        $type = (string) $rm->getReturnType();
655
        switch ($type) {
656
            case '':       return;
657
            case 'string': return '';
658
            case 'int':    return 0;
659
            case 'float':  return 0.0;
660
            case 'bool':   return false;
661
            case 'array':  return [];
662
663
            case 'callable':
664
            case 'Closure':
665
                return function () {};
666
667
            case 'Traversable':
668
            case 'Generator':
669
                // Remove eval() when minimum version >=5.5
670
                $generator = eval('return function () { yield; };');
671
                return $generator();
672
673
            case 'self':
674
                return \Mockery::mock($rm->getDeclaringClass()->getName());
675
676
            default:
677
                return \Mockery::mock($type);
678
        }
679
    }
680
681
    public function shouldHaveReceived($method, $args = null)
682
    {
683
        $expectation = new \Mockery\VerificationExpectation($this, $method);
684
        if (null !== $args) {
685
            $expectation->withArgs($args);
0 ignored issues
show
Documentation introduced by
$args is of type null, but the function expects a array|object<Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
686
        }
687
        $expectation->atLeast()->once();
688
        $director = new \Mockery\VerificationDirector($this->_mockery_getReceivedMethodCalls(), $expectation);
689
        $this->_mockery_expectations_count++;
690
        $director->verify();
691
        return $director;
692
    }
693
694
    public function shouldNotHaveReceived($method, $args = null)
695
    {
696
        $expectation = new \Mockery\VerificationExpectation($this, $method);
697
        if (null !== $args) {
698
            $expectation->withArgs($args);
0 ignored issues
show
Documentation introduced by
$args is of type null, but the function expects a array|object<Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
699
        }
700
        $expectation->never();
701
        $director = new \Mockery\VerificationDirector($this->_mockery_getReceivedMethodCalls(), $expectation);
702
        $this->_mockery_expectations_count++;
703
        $director->verify();
704
        return null;
705
    }
706
707
    protected static function _mockery_handleStaticMethodCall($method, array $args)
708
    {
709
        try {
710
            $associatedRealObject = \Mockery::fetchMock(__CLASS__);
711
            return $associatedRealObject->__call($method, $args);
712
        } catch (\BadMethodCallException $e) {
713
            throw new \BadMethodCallException(
714
                'Static method ' . $associatedRealObject->mockery_getName() . '::' . $method
715
                . '() does not exist on this mock object'
716
            );
717
        }
718
    }
719
720
    protected function _mockery_getReceivedMethodCalls()
721
    {
722
        return $this->_mockery_receivedMethodCalls ?: $this->_mockery_receivedMethodCalls = new \Mockery\ReceivedMethodCalls();
723
    }
724
725
    protected function _mockery_handleMethodCall($method, array $args)
726
    {
727
        $this->_mockery_getReceivedMethodCalls()->push(new \Mockery\MethodCall($method, $args));
728
729
        $rm = $this->mockery_getMethod($method);
730
        if ($rm && $rm->isProtected() && !$this->_mockery_allowMockingProtectedMethods) {
731
            if ($rm->isAbstract()) {
732
                return;
733
            }
734
735
            try {
736
                $prototype = $rm->getPrototype();
737
                if ($prototype->isAbstract()) {
738
                    return;
739
                }
740
            } catch (\ReflectionException $re) {
741
                // noop - there is no hasPrototype method
742
            }
743
744
            return call_user_func_array("parent::$method", $args);
745
        }
746
747
        if (isset($this->_mockery_expectations[$method])
748
        && !$this->_mockery_disableExpectationMatching) {
749
            $handler = $this->_mockery_expectations[$method];
750
751
            try {
752
                return $handler->call($args);
753
            } catch (\Mockery\Exception\NoMatchingExpectationException $e) {
754
                if (!$this->_mockery_ignoreMissing && !$this->_mockery_deferMissing) {
755
                    throw $e;
756
                }
757
            }
758
        }
759
760
        if (!is_null($this->_mockery_partial) && method_exists($this->_mockery_partial, $method)) {
761
            return call_user_func_array(array($this->_mockery_partial, $method), $args);
762
        } elseif ($this->_mockery_deferMissing && is_callable("parent::$method")) {
763
            return call_user_func_array("parent::$method", $args);
764
        } elseif ($method == '__toString') {
765
            // __toString is special because we force its addition to the class API regardless of the
766
            // original implementation.  Thus, we should always return a string rather than honor
767
            // _mockery_ignoreMissing and break the API with an error.
768
            return sprintf("%s#%s", __CLASS__, spl_object_hash($this));
769
        } elseif ($this->_mockery_ignoreMissing) {
770
            if (\Mockery::getConfiguration()->mockingNonExistentMethodsAllowed() || (method_exists($this->_mockery_partial, $method) || is_callable("parent::$method"))) {
771
                if ($this->_mockery_defaultReturnValue instanceof \Mockery\Undefined) {
772
                    return call_user_func_array(array($this->_mockery_defaultReturnValue, $method), $args);
773
                } elseif (null === $this->_mockery_defaultReturnValue) {
774
                    return $this->mockery_returnValueForMethod($method);
775
                } else {
776
                    return $this->_mockery_defaultReturnValue;
777
                }
778
            }
779
        }
780
        throw new \BadMethodCallException(
781
            'Method ' . __CLASS__ . '::' . $method . '() does not exist on this mock object'
782
        );
783
    }
784
785
    /**
786
     * Uses reflection to get the list of all
787
     * methods within the current mock object
788
     * 
789
     * @return array
790
     */
791
    protected function mockery_getMethods()
792
    {
793
        if (static::$_mockery_methods) {
794
            return static::$_mockery_methods;
795
        }
796
797
        $methods = array();
0 ignored issues
show
Unused Code introduced by
$methods is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
798
799
        if (isset($this->_mockery_partial)) {
800
            $reflected = new \ReflectionObject($this->_mockery_partial);
801
        } else {
802
            $reflected = new \ReflectionClass($this);
803
        }
804
        $methods = $reflected->getMethods();
805
806
        return static::$_mockery_methods = $methods;
0 ignored issues
show
Documentation Bug introduced by
It seems like $methods of type array<integer,object<ReflectionMethod>> is incompatible with the declared type array<integer,object<Mockery\ReflectionMethod>> of property $_mockery_methods.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
807
    }
808
809
    /**
810
     * @return array
811
     */
812
    private function getNonPublicMethods()
813
    {
814
        return array_map(
815
            function ($method) {
816
                return $method->getName();
817
            },
818
            array_filter($this->mockery_getMethods(), function ($method) {
819
                return !$method->isPublic();
820
            })
821
        );
822
    }
823
}
824