@noinspection PhpMissingParentCallCommonInspection

@inheritDoc
164058
protected function createInstance(JsonApiRequest $request, ErrorCollection $errors)
    {
        // for Roles allowed to define ID on creation that's why we don't use default (parent) method

        $instance = $this->getModel()->newInstance();

        $instance->setAttribute($instance->getKeyName(), $request->getId());

        return $instance;
    }
728050
function parent($new = null, $return_entity = false)
    {
        if (isset($new)){
            if ($new instanceof Entity){
                $this->_parent = $new;
                $new = $new->uri();
            }else{
                $this->_parent = null; // for reloading
            }
            if ($new != $this->_attributes['parent']){
                $this->change('parent', $new);
                $this->change('order', Entity::MAX_ORDER);
                $this->change('uri', $new.'/'.$this->_attributes['name']);
            }
        }
        if ($return_entity){
            if (!isset($this->_parent)){
                if (isset($this->_attributes['parent'])){
                    $this->_parent = Data::read($this->_attributes['parent']);
                }else{
                    $this->_parent = false;
                }
            }
            return $this->_parent;
        }
        return $this->_attributes['parent'];
    }
1352370
public function parent($parent = false)
    {
        if ($parent) {
            $this->parents = !is_array($parent) ? [$parent] : $parent;

            if (func_num_args() > 1) {
                $this->parents = func_get_args();
            }
        }

        return $this;
    }
698993
public function define($name, $parameters = [], $parent = null, $children = [])
    {
        if (is_array($parent)) {
            $children = $parent;
            $parent = null;
        }
        if ($parent) {
            if (!array_has($this->items, $parent))
                throw new InvalidArgumentException("{$parent} does not exist");

            $name = "{$parent}.children.{$name}";

            if (empty($parameters['icon'])) $parameters['icon'] = 'fa-circle-o';
        } else {
            if (empty($parameters['icon'])) $parameters['icon'] = '';
        }
        if (empty($parameters['sort'])) $parameters['sort'] = 10;

        array_set($this->items, $name, $parameters);

        foreach ($children as $childName => $child) {
            $this->define($childName, $child, $name);
        }
    }
316046
public function call($method, array $arguments = [])
    {
        if ($this->value === null || isset($this->whitelist[$method]) || isset($this->whitelist['*']) || ($this->value instanceof ProtectedContextAwareInterface && $this->value->allowsCallOfMethod($method))) {
            return parent::call($method, $arguments);
        }
        throw new NotAllowedException('Method "' . $method . '" is not callable in untrusted context', 1369043080);
    }
412744
public function detectParent()
    {
        // Look for a string, then a number (the parent id), followed by a non-action
        // string, then possiby a number and/or an action string and then the end
        $pattern = '#([a-z-]+)/(\d+)/(?!'.implode('|', $this->actions).')[a-z-]+(?:/\d+)?(/('.implode('|', $this->actions).'))?$#i';
        if (preg_match($pattern, $this->path, $matches)) {
            return [$matches[1], $matches[2]];
        }

        return false;
    }
461009
function getParentFunction() {
		for ($i = $this->count() - 1; $i >= 0; $i --) {
			$item = $this->statements[$i];
			if ($item->type === "FUNCTION") {
				return $item;
			}
		}
		// In case of a empty stack, we are at the root of a PHP file (with no class or function).
		// We return the default values
		return $this->getDefaultItem();
	}
840083
function in($parent)
    {
        if (!$this->is_exists() || ($parent instanceof Entity && !$parent->is_exists())) return false;
        if ($this->eq($parent)) return true;
        return $this->child_of($parent);
    }
770177
protected function requiresParent(string $methodName)
    {
        if (in_array('*', $this->requiresParent)) {
            return true;
        }

        return in_array($methodName, $this->requiresParent);
    }
69810
public function hasParent($parentClassName)
    {
        $found = false;

        $this->alongParents(function ($parent) use ($parentClassName, &$found) {
            if ($parent instanceof $parentClassName) {
                $found = true;

                return false;
            }

            return true;
        });

        return $found;
    }
136018
private static function checkCallable(
        $classInstance,
        callable $callable,
        $method = null
    ) {
        // if there are args and debug mode is on
        if ($method && self::$checkCallableParameters) {

            $originalMethodReflection = new \ReflectionMethod($classInstance, $method);

            if ($originalMethodReflection->getNumberOfParameters() === 0) {
                return;
            }

            $originalMethodReflectionParameters = $originalMethodReflection->getParameters();

            if (is_array($callable)) {
                $callableReflection = new \ReflectionMethod($callable[0], $callable[1]);
                $callableReflectionParameters = $callableReflection->getParameters();
            } elseif ($callable instanceof \Closure) {
                $callableReflection = new \ReflectionFunction($callable);
                $callableReflectionParameters = $callableReflection->getParameters();
            }

            $originalParameters = self::getReflectionParameters($originalMethodReflectionParameters);

            $callableParameters = self::getReflectionParameters($callableReflectionParameters);

            $parameterOffset = 0;

            // remove default parameters
            if ($method && $callableParameters && $callable instanceof \Closure === false) {
                $callableParameters = array_slice($callableParameters, 1);

                $parameterOffset = 1;
            }

            /**
             * [
             *      0 => [
             *          'original' => 'resourceLocation'
             *          'callable' => 'uri'
             *          'dirty' => true
             *      ],
             *
             *      1 => [
             *          'original' => 'message'
             *          'callable' => null
             *          'missing' => true
             */

            $parameterMeta = array_map(
                function ($originalParameter, $callableParameter) {
                    return ['original' => $originalParameter, 'callable' => $callableParameter];
                },
                $originalParameters,
                $callableParameters
            );

            $parameterDiff = array_filter(
                $parameterMeta,
                function ($item) {
                    return $item['original'] !== $item['callable'];
                }
            ); // remove matching fields, preserves keys

            if ($parameterDiff) {
                self::findParameterIssues(
                    $method,
                    $callableParameters,
                    $parameterDiff,
                    $parameterOffset
                );
            }
        }
    }
1109313
final protected function assertInterfaceExtends(string $parentInterfaceName, string $interfaceName): void
    {
        $this->assertInterfaceExists($parentInterfaceName);
        $this->assertInterfaceExists($interfaceName);

        $reflection = new \ReflectionClass($interfaceName);

        self::assertTrue($reflection->isSubclassOf($parentInterfaceName), \sprintf(
            'Failed asserting that interface "%s" extends "%s".',
            $interfaceName,
            $parentInterfaceName
        ));
    }
569596
private function parentIsNotFromProvider($conjunction, $parentProviderName)
    {
        if (!empty($this->expression)) {
            $this->expression[] = $conjunction;
        }

        $index              = \count($this->variables);
        $this->expression[] = \sprintf(self::PARENT_IS_NOT_FROM_PROVIDER_EXPRESSION, $index);
        $this->variables[]  = $parentProviderName;
        $this->compiled     = null;

        return $this;
    }
1096930
private function callOnce ($fn) 
    {
        return function (...$args) use ($fn) {
            if ($fn === null) return;
            $fn(...$args);
            $fn = null;
        };
    }
55373
public function countParents(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collParentsPartial && !$this->isNew();
        if (null === $this->collParents || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collParents) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getParents());
            }

            $query = ChildSkillDependencyQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySkillRelatedByParentId($this)
                ->count($con);
        }

        return count($this->collParents);
    }
1308622
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Stmt\ClassMethod || ! $parent instanceof InterfaceModelInterface) {
            throw new Exception('MethodNodeParser is made to parse a method node');
        }

        // Retrieve visibility
        $function = new FunctionModel();
        $function->setVisibility(MethodVisibilityHelper::getVisibility($node));

        // If no private / protected methods parsing is required
        if (! $function->isPublic() && ! $this->config->hasPrivateParsing()) {
            return;
        }

        $function->setParentNode($parent);
        $function->setName($node->name);
        $function->setIsFinal($node->isFinal());
        $function->setIsStatic($node->isStatic());
        $function->setIsAbstract($node->isAbstract());

        $this->parseFunction($node, $function);

        $parent->addFunction($function);

        if ($this->autoGetterOrSetter($function, $parent)) {
            return;
        }
        if (($documentation = $node->getDocComment()) !== null) {
            $this->documentationNodeParser->invoke($documentation, $function);
        }
    }
979786
private function skip(ContextInterface $context)
    {
        $dataStack = $context->getDataStack();
        $metadataStack = $context->getMetadataStack();
        $references = [];
        $depth = 0;

        for ($index = count($metadataStack) - 1; $index >= 0; --$index) {
            $metadata = $metadataStack[$index];
            $data = $dataStack[$index];

            if ($metadata instanceof ClassMetadataInterface) {
                $hash = spl_object_hash($data);

                if (!isset($references[$hash])) {
                    $references[$hash] = 0;
                }

                if (++$references[$hash] > $this->circularReferenceLimit) {
                    return true;
                }
            }

            if ($metadata instanceof TypeMetadataInterface) {
                ++$depth;
            }

            if (!$metadata instanceof PropertyMetadataInterface) {
                continue;
            }

            ++$depth;

            if (!$metadata->hasMaxDepth()) {
                continue;
            }

            if ($depth > $metadata->getMaxDepth()) {
                return true;
            }
        }

        return false;
    }