Eloquent\Phony\Mock\Builder\MockDefinition::buildMethods PHP Method

buildMethods() private method

private buildMethods ( )
    private function buildMethods()
    {
        if (null !== $this->methods) {
            return;
        }
        $methods = array();
        $unmockable = array();
        if ($typeName = $this->parentClassName()) {
            $type = $this->types[strtolower($typeName)];
            foreach ($type->getMethods() as $method) {
                if ($method->isPrivate()) {
                    continue;
                }
                $methodName = $method->getName();
                if ($method->isConstructor() || $method->isFinal()) {
                    $unmockable[$methodName] = true;
                } else {
                    $methods[$methodName] = new RealMethodDefinition($method, $methodName);
                }
            }
        }
        $traitMethods = array();
        foreach ($this->traitNames() as $typeName) {
            $type = $this->types[strtolower($typeName)];
            foreach ($type->getMethods() as $method) {
                $methodName = $method->getName();
                $methodDefinition = new TraitMethodDefinition($method, $methodName);
                if (!$method->isAbstract()) {
                    $traitMethods[] = $methodDefinition;
                }
                if (isset($unmockable[$methodName])) {
                    continue;
                }
                if (!isset($methods[$methodName])) {
                    $methods[$methodName] = $methodDefinition;
                }
            }
        }
        foreach ($this->interfaceNames() as $typeName) {
            $type = $this->types[strtolower($typeName)];
            foreach ($type->getMethods() as $method) {
                $methodName = $method->getName();
                if (isset($unmockable[$methodName])) {
                    continue;
                }
                if (!isset($methods[$methodName])) {
                    $methods[$methodName] = new RealMethodDefinition($method, $methodName);
                }
            }
        }
        if ($this->isRelaxedKeywordsSupported) {
            // class is the only keyword that can not be used as a method name
            unset($methods['class']);
            // @codeCoverageIgnoreStart
        } else {
            $methodNames = array_keys($methods);
            $tokens = token_get_all('<?php ' . implode(' ', $methodNames));
            foreach ($methodNames as $index => $methodName) {
                $tokenIndex = $index * 2 + 1;
                if (!is_array($tokens[$tokenIndex]) || $tokens[$tokenIndex][0] !== T_STRING) {
                    unset($methods[$methodName]);
                }
            }
        }
        // @codeCoverageIgnoreEnd
        foreach ($this->customStaticMethods as $methodName => $method) {
            list($callback, $reflector) = $method;
            $methods[$methodName] = new CustomMethodDefinition(true, $methodName, $callback, $reflector);
        }
        foreach ($this->customMethods as $methodName => $method) {
            list($callback, $reflector) = $method;
            $methods[$methodName] = new CustomMethodDefinition(false, $methodName, $callback, $reflector);
        }
        $this->methods = new MethodDefinitionCollection($methods, $traitMethods);
    }