protected function removeImpossibleArraySubtypes(array $types): array
    {
        $subTypes = $this->getSubTypes();

        if (count($subTypes) === 0) {
            return $types;
        }

        $subHandler = $this->setTypes($subTypes);

        foreach ($this->value as $item) {
            $subHandler = $subHandler->setTypes($subHandler->getPossibleTypes($item));
        }

        $possibleSubTypes = $subHandler->types;

        return count($possibleSubTypes) === count($subTypes)
            ? $types
            : array_filter($types, function($type) use ($possibleSubTypes) {
                return substr($type, -2) !== '[]' || in_array(substr($type, 0, -2), $possibleSubTypes);
            });
    }
protected function removeImpossibleArraySubtypes(array $types): array
    {
        $subTypes = $this->getSubTypes();

        if (count($subTypes) === 0) {
            return $types;
        }

        $subHandler = $this->setTypes($subTypes);

        foreach ($this->value as $item) {
            $subHandler = $subHandler->setTypes($subHandler->getPossibleTypes($item));
        }

        $possibleSubTypes = $subHandler->types;

        return count($possibleSubTypes) === count($subTypes)
            ? $types
            : array_filter($types, function($type) use ($possibleSubTypes) {
                return substr($type, -2) !== '[]' || in_array(substr($type, 0, -2), $possibleSubTypes);
            });
    }
protected function removeImpossibleArraySubtypes ( array $ types ) : array { $ subTypes = $ this -> getSubTypes ( ) ; if ( count ( $ subTypes ) === 0 ) { return $ types ; } $ subHandler = $ this -> setTypes ( $ subTypes ) ; foreach ( $ this -> value as $ item ) { $ subHandler = $ subHandler -> setTypes ( $ subHandler -> getPossibleTypes ( $ item ) ) ; } $ possibleSubTypes = $ subHandler -> types ; return count ( $ possibleSubTypes ) === count ( $ subTypes ) ? $ types : array_filter ( $ types , function ( $ type ) use ( $ possibleSubTypes ) { return substr ( $ type , - 2 ) !== '[]' || in_array ( substr ( $ type , 0 , - 2 ) , $ possibleSubTypes ) ; } ) ; }
Remove subtypes that aren't available for each item.

@param array    $types
@return array
Remove subtypes that aren t available for each item .