public function getFullName(): ?string
    {
        if (null === $this->getName()) {
            return null;
        }

        if (!($this instanceof ElementHasParentInterface)) {
            return $this->getName();
        }

        $parents = $this->getParents();

        if ($parents->empty()) {
            return $this->getName();
        }

        $chain = $parents->append($this);
        $sliced = new Collection();
        foreach ($chain->reverse() as $el) {
            if (null === $el->getName()) {
                break;
            }
            $sliced->prepend($el);
        }
        if (1 === count($sliced)) {
            return $this->getName();
        }

        $names = [];
        $first = $sliced->first();
        foreach ($sliced as $el) {
            if ($el === $first) {
                $names[] = $el->getName();
            } else {
                $names[] = $el->getParent()->searchSame($el);
            }
        }

        return $names[0] . '[' . implode('][', array_slice($names, 1)) . ']';

    }
public function getFullName(): ?string
    {
        if (null === $this->getName()) {
            return null;
        }

        if (!($this instanceof ElementHasParentInterface)) {
            return $this->getName();
        }

        $parents = $this->getParents();

        if ($parents->empty()) {
            return $this->getName();
        }

        $chain = $parents->append($this);
        $sliced = new Collection();
        foreach ($chain->reverse() as $el) {
            if (null === $el->getName()) {
                break;
            }
            $sliced->prepend($el);
        }
        if (1 === count($sliced)) {
            return $this->getName();
        }

        $names = [];
        $first = $sliced->first();
        foreach ($sliced as $el) {
            if ($el === $first) {
                $names[] = $el->getName();
            } else {
                $names[] = $el->getParent()->searchSame($el);
            }
        }

        return $names[0] . '[' . implode('][', array_slice($names, 1)) . ']';

    }
public function getFullName ( ) : ? string { if ( null === $ this -> getName ( ) ) { return null ; } if ( ! ( $ this instanceof ElementHasParentInterface ) ) { return $ this -> getName ( ) ; } $ parents = $ this -> getParents ( ) ; if ( $ parents -> empty ( ) ) { return $ this -> getName ( ) ; } $ chain = $ parents -> append ( $ this ) ; $ sliced = new Collection ( ) ; foreach ( $ chain -> reverse ( ) as $ el ) { if ( null === $ el -> getName ( ) ) { break ; } $ sliced -> prepend ( $ el ) ; } if ( 1 === count ( $ sliced ) ) { return $ this -> getName ( ) ; } $ names = [ ] ; $ first = $ sliced -> first ( ) ; foreach ( $ sliced as $ el ) { if ( $ el === $ first ) { $ names [ ] = $ el -> getName ( ) ; } else { $ names [ ] = $ el -> getParent ( ) -> searchSame ( $ el ) ; } } return $ names [ 0 ] . '[' . implode ( '][' , array_slice ( $ names , 1 ) ) . ']' ; }
Full element's name includes all it's parents names
@return string|null
Full element s name includes all it s parents names