src/Mock/Handle/HandleFactory.php
public function staticHandle($class): StaticHandle
    {
        if ($class instanceof StaticHandle) {
            return $class;
        }

        if ($class instanceof Handle) {
            $class = $class->class();
        } elseif ($class instanceof Mock) {
            $class = new ReflectionClass($class);
        } elseif (is_string($class)) {
            try {
                $class = new ReflectionClass($class);
            } catch (ReflectionException $e) {
                throw new NonMockClassException($class, $e);
            }
        } elseif (!$class instanceof ReflectionClass) {
            throw new InvalidMockClassException($class);
        }

        if (!$class->isSubclassOf(Mock::class)) {
            throw new NonMockClassException($class->getName());
        }

        $handleProperty = $class->getProperty('_staticHandle');
        $handleProperty->setAccessible(true);

        if ($handle = $handleProperty->getValue(null)) {
            return $handle;
        }

        $handle = new StaticHandle(
            $class,
            (object) [
                'defaultAnswerCallback' =>
                    [StubData::class, 'forwardsAnswerCallback'],
                'stubs' => (object) [],
                'isRecording' => true,
            ],
            $this->stubFactory,
            $this->stubVerifierFactory,
            $this->emptyValueFactory,
            $this->assertionRenderer,
            $this->assertionRecorder,
            $this->invoker
        );

        $handleProperty->setValue(null, $handle);

        return $handle;
    }
public function staticHandle($class): StaticHandle
    {
        if ($class instanceof StaticHandle) {
            return $class;
        }

        if ($class instanceof Handle) {
            $class = $class->class();
        } elseif ($class instanceof Mock) {
            $class = new ReflectionClass($class);
        } elseif (is_string($class)) {
            try {
                $class = new ReflectionClass($class);
            } catch (ReflectionException $e) {
                throw new NonMockClassException($class, $e);
            }
        } elseif (!$class instanceof ReflectionClass) {
            throw new InvalidMockClassException($class);
        }

        if (!$class->isSubclassOf(Mock::class)) {
            throw new NonMockClassException($class->getName());
        }

        $handleProperty = $class->getProperty('_staticHandle');
        $handleProperty->setAccessible(true);

        if ($handle = $handleProperty->getValue(null)) {
            return $handle;
        }

        $handle = new StaticHandle(
            $class,
            (object) [
                'defaultAnswerCallback' =>
                    [StubData::class, 'forwardsAnswerCallback'],
                'stubs' => (object) [],
                'isRecording' => true,
            ],
            $this->stubFactory,
            $this->stubVerifierFactory,
            $this->emptyValueFactory,
            $this->assertionRenderer,
            $this->assertionRecorder,
            $this->invoker
        );

        $handleProperty->setValue(null, $handle);

        return $handle;
    }
public function staticHandle ( $ class ) : StaticHandle { if ( $ class instanceof StaticHandle ) { return $ class ; } if ( $ class instanceof Handle ) { $ class = $ class -> class ( ) ; } elseif ( $ class instanceof Mock ) { $ class = new ReflectionClass ( $ class ) ; } elseif ( is_string ( $ class ) ) { try { $ class = new ReflectionClass ( $ class ) ; } catch ( ReflectionException $ e ) { throw new NonMockClassException ( $ class , $ e ) ; } } elseif ( ! $ class instanceof ReflectionClass ) { throw new InvalidMockClassException ( $ class ) ; } if ( ! $ class -> isSubclassOf ( Mock :: class ) ) { throw new NonMockClassException ( $ class -> getName ( ) ) ; } $ handleProperty = $ class -> getProperty ( '_staticHandle' ) ; $ handleProperty -> setAccessible ( true ) ; if ( $ handle = $ handleProperty -> getValue ( null ) ) { return $ handle ; } $ handle = new StaticHandle ( $ class , ( object ) [ 'defaultAnswerCallback' => [ StubData :: class , 'forwardsAnswerCallback' ] , 'stubs' => ( object ) [ ] , 'isRecording' => true , ] , $ this -> stubFactory , $ this -> stubVerifierFactory , $ this -> emptyValueFactory , $ this -> assertionRenderer , $ this -> assertionRecorder , $ this -> invoker ) ; $ handleProperty -> setValue ( null , $ handle ) ; return $ handle ; }
Create a new static handle.

@param Mock|Handle|ReflectionClass|string $class The class.

@return StaticHandle  The newly created handle.
@throws MockException If the supplied class name is not a mock class.
Create a new static handle .