@param TypeDoc $doc
@param array   $siblingsDoc

@return array

@throws \ReflectionException
17318
protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc) : array
    {
        // CollectionDoc should be managed as ArrayDoc
        if (!$doc instanceof ArrayDoc && get_class($doc) !== CollectionDoc::class) {
            return $siblingsDoc;
        }
        /** @var $doc ArrayDoc|CollectionDoc */
        // add mandatory "items" field
        if ($doc instanceof ArrayDoc && null !== $doc->getItemValidation()) {
            $siblingsDoc['items'] = $this->normalize($doc->getItemValidation());
        } else {
            $siblingsDoc['items']['type'] = $this->guessItemsType($doc->getSiblingList());
        }

        return $siblingsDoc;
    }
432685
public function normalize(TypeDoc $doc) : array
    {
        $siblingsDoc = $paramDocRequired = [];

        $siblingsDoc = $this->appendArrayDoc($doc, $siblingsDoc);
        list (
            $siblingsDoc,
            $paramDocRequired
            ) = $this->appendObjectDoc($doc, $siblingsDoc, $paramDocRequired);

        $format = ($doc instanceof StringDoc ? $doc->getFormat() : null);

        return $this->appendIfValueNotNull('description', $doc->getDescription())
            + ['type' => $this->schemaTypeNormalizer->normalize($doc)]
            + $this->appendIfValueNotNull('format', $format)
            + ['nullable' => $doc->isNullable()]
            + $paramDocRequired
            + $this->appendIfValueNotNull('default', $doc->getDefault())
            + $this->appendIfValueNotNull('example', $doc->getExample())
            + $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
            + $this->getMinMaxDoc($doc)
            + $siblingsDoc
        ;
    }
445121
public function generate(
        $bundleDir,
        $bundleNamespace,
        $bundleName,
        $document
    ) {
        $this->readServicesAndParams($bundleDir);

        $basename = $this->getBundleBaseName($document);

        if (!is_null($this->json)) {
            $this->json->setNamespace($bundleNamespace);
        }

        // add more info to the fields array
        $mapper = $this->mapper;
        $fields = array_map(
            function ($field) use ($mapper) {
                return $mapper->map($field, $this->json);
            },
            $this->mapper->buildFields($this->json)
        );

        $parameters = $this->parameterBuilder
            ->reset()
            ->setParameter('document', $document)
            ->setParameter('base', $bundleNamespace)
            ->setParameter('bundle', $bundleName)
            ->setParameter('json', $this->json)
            ->setParameter('fields', $fields)
            ->setParameter('basename', $basename)
            ->setParameter('isrecordOriginFlagSet', $this->json->isRecordOriginFlagSet())
            ->setParameter('recordOriginModifiable', $this->json->isRecordOriginModifiable())
            ->setParameter('isVersioning', $this->json->isVersionedService())
            ->setParameter('collection', $this->json->getServiceCollection())
            ->setParameter('indexes', $this->json->getIndexes())
            ->setParameter('textIndexes', $this->json->getAllTextIndexes())
            ->setParameter('solrFields', $this->json->getSolrFields())
            ->setParameter('solrAggregate', $this->json->getSolrAggregate())
            ->getParameters();

        $this->generateDocument($parameters, $bundleDir, $document);
        $this->generateSerializer($parameters, $bundleDir, $document);
        $this->generateModel($parameters, $bundleDir, $document);

        if ($this->json instanceof JsonDefinition && $this->json->hasFixtures() === true) {
            $this->generateFixtures($parameters, $bundleDir, $document);
        }

        if ($this->generateController) {
            $this->generateController($parameters, $bundleDir, $document);
        }

        $this->persistServicesAndParams();
    }
1166850
private function cascadeDetach($document, array &$visited)
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        foreach ($class->propertyMetadata as $mapping) {
            if (!$mapping->isCascadeDetach) {
                continue;
            }
            $relatedDocuments = $class->getPropertyMetadata($mapping->name)->getValue($document);
            if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) {
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
                    // Unwrap so that foreach() does not initialize
                    $relatedDocuments = $relatedDocuments->unwrap();
                }
                foreach ($relatedDocuments as $relatedDocument) {
                    $this->doDetach($relatedDocument, $visited);
                }
            } elseif ($relatedDocuments !== null) {
                $this->doDetach($relatedDocuments, $visited);
            }
        }
    }
14435
protected function appendMisc(TypeDoc $docObject) : array
    {
        $docArray = [];
        $docArray = $this->appendIfNotNull($docArray, 'default', $docObject->getDefault());
        $docArray = $this->appendIfNotNull($docArray, 'example', $docObject->getExample());

        if ($docObject instanceof StringDoc) {
            $docArray = $this->appendIfNotNull($docArray, 'format', $docObject->getFormat());
        } elseif ($docObject instanceof ArrayDoc && null !== $docObject->getItemValidation()) {
            $docArray['item_validation'] = $this->normalize($docObject->getItemValidation());
        }

        return $docArray;
    }
289820
protected function getServerErrorsExtraSchemaList(ServerDoc $doc) : array
    {
        $list = [];
        foreach ($doc->getGlobalErrorList() as $errorDoc) {
            $key = $this->definitionRefResolver->getErrorDefinitionId(
                $errorDoc,
                DefinitionRefResolver::CUSTOM_ERROR_DEFINITION_TYPE
            );
            $list[$key] = $this->errorDocNormalizer->normalize($errorDoc);
        }

        foreach ($doc->getServerErrorList() as $errorDoc) {
            $key = $this->definitionRefResolver->getErrorDefinitionId(
                $errorDoc,
                DefinitionRefResolver::SERVER_ERROR_DEFINITION_TYPE
            );
            $list[$key] = $this->errorDocNormalizer->normalize($errorDoc);
        }

        return $list;
    }
950429
protected function kneadHref( \DOMDocument $doc, $type, $pos ) {

		$urls = $doc->getElementsByTagName( 'a' );
		foreach ( $urls as $url ) {
			/** @var \DOMElement $url */
			$current_url = '' . $url->getAttribute( 'href' ); // Stringify

			// Is this the the attributionUrl?
			if ( $url->getAttribute( 'rel' ) === 'cc:attributionURL' ) {
				$url->parentNode->replaceChild(
					$doc->createTextNode( $url->nodeValue ),
					$url
				);
				continue;
			}

			// Don't touch empty urls
			if ( ! trim( $current_url ) ) {
				continue;
			}

			// WordPress auto wraps images in a href tags.
			// For example: <a href="some_image-original.png"><img src="some_image-300x200.png" /></a>
			// This causes an EPUB validation error of: hyperlink to non-standard resource ( of type 'image/...' )
			// We fix this by removing the href
			if ( $url->childNodes->length ) {
				foreach ( $url->childNodes as $node ) {
					/** @var \DOMElement $node */
					if ( 'img' === $node->nodeName && $this->fuzzyImageNameMatch( $current_url, $node->getAttribute( 'src' ) ) ) {
						$url->removeAttribute( 'href' );
						continue 2;
					}
				}
			}

			// Determine if we are trying to link to our own internal content
			$internal_url = $this->fuzzyHrefMatch( $current_url, $pos );
			if ( false !== $internal_url ) {
				$url->setAttribute( 'href', $internal_url );
				continue;
			}

			// Canonicalize, fix typos, remove garbage
			if ( isset( $current_url[0] ) && '#' !== $current_url[0] ) {
				$url->setAttribute( 'href', \Pressbooks\Sanitize\canonicalize_url( $current_url ) );
			}
		}

		return $doc;
	}
837343
protected function appendDocEnum(TypeDoc $docObject) : array
    {
        $docArray = [];
        foreach ($docObject->getAllowedValueList() as $value) {
            $docArray['allowedValues'][] = $value;
        }

        return $docArray;
    }
194989
protected function getDefaultSchemaList(ServerDoc $doc) : array
    {
        $propertyList = [
            'code' => [
                'type' => 'integer',
            ],
        ];

        $errorList = array_merge($doc->getServerErrorList(), $doc->getGlobalErrorList());
        $errorList = array_reduce(
            array_map(
                function (MethodDoc $methodDoc) {
                    return $methodDoc->getCustomErrorList();
                },
                $doc->getMethodList()
            ),
            function (array $carry, array $subErrorList) {
                $carry = array_merge($carry, $subErrorList);

                return $carry;
            },
            $errorList
        );
        $codeList = array_unique(
            array_map(
                function (ErrorDoc $errorDoc) {
                    return $errorDoc->getCode();
                },
                $errorList
            )
        );

        if (count($codeList) > 0) {
            $propertyList['code']['enum'] = array_values($codeList);
        }

        return [
            'Default-Error' => [
                'allOf' => [
                    $this->shapeNormalizer->getErrorShapeDefinition(),
                    [
                        'type' => 'object',
                        'properties' => $propertyList,
                    ],
                ],
            ],
        ];
    }
366170
protected function sibling($node, $siblingDir = 'nextSibling')
    {
        $nodes = [];

        $currentNode = $this->getNode(0);
        do {
            if ($node !== $currentNode && XML_ELEMENT_NODE === $node->nodeType) {
                $nodes[] = $node;
            }
        } while ($node = $node->$siblingDir);

        return $nodes;
    }
1176352
private function cascadePersist($document, array &$visited)
    {
        $class = $this->dm->getClassMetadata(get_class($document));

        $associationMetadata = array_filter(
            $class->associationMetadata,
            function ($assoc) {
                return $assoc->isCascadePersist;
            }
        );

        foreach ($associationMetadata as $attributeName => $mapping) {
            $relatedDocuments = $mapping->getValue($document);

            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
                if ($relatedDocuments instanceof PersistentCollectionInterface) {
                    if ($relatedDocuments->getOwner() !== $document) {
                        $relatedDocuments = $this->fixPersistentCollectionOwnership($relatedDocuments, $document, $mapping);
                    }
                    // Unwrap so that foreach() does not initialize
                    $relatedDocuments = $relatedDocuments->unwrap();
                }

                $count = 0;
                foreach ($relatedDocuments as $relatedKey => $relatedDocument) {
                    if ($mapping->embedded) {
                        list(, $knownParent, ,) = $this->getParentAssociation($relatedDocument);

                        if ($knownParent && $knownParent !== $document) {
                            $relatedDocument               = clone $relatedDocument;
                            $relatedDocuments[$relatedKey] = $relatedDocument;
                        }

                        $pathKey = $mapping->isNumericIndexed() ? $count++ : (string)$relatedKey;
                        $this->setParentAssociation($relatedDocument, $mapping, $document, $mapping->name, $pathKey);
                    }
                    $this->doPersist($relatedDocument, $visited);
                }
            } elseif ($relatedDocuments !== null) {
                if ($mapping->embedded) {
                    list(, $knownParent, ,) = $this->getParentAssociation($relatedDocuments);
                    if ($knownParent && $knownParent !== $document) {
                        $relatedDocuments = clone $relatedDocuments;
                        $mapping->setValueAndWakeProxy($document, $relatedDocuments);
                    }
                    $this->setParentAssociation($relatedDocuments, $mapping, $document, $mapping->name);
                }
                $this->doPersist($relatedDocuments, $visited);
            }
        }
    }
967195
public function normalize(TypeDoc $docObject) : array
    {
        $docArray = [];

        $docArray = $this->appendIfNotNull($docArray, 'description', $docObject->getDescription());

        return $docArray
            + ['type' => $this->normalizeSchemaType($docObject)]
            + ['nullable' => $docObject->isNullable()]
            + ['required' => $docObject->isRequired()]
            + $this->appendMisc($docObject)
            + $this->appendDocEnum($docObject)
            + $this->appendMinMax($docObject)
            + $this->appendCollectionDoc($docObject)
        ;
    }
691840
public function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
    if ($this->has_changed()) {
      // If the name as changed so it's always output.
      $this->_unsavedKeys['name'] = true;

      $childNode = $node->appendChild($doc->createElement($this->getNodeName()));
      parent::populateXmlDoc($doc, $childNode, $obj, $nested);
    }
  }
1251130
public function toDOM(\DOMDocument $doc): \DOMNode
    {
        $paragraph = $doc->createElement('p');

        $this->customAttributesToDOM($paragraph);
        $this->containerToDOM($doc, $paragraph);

        return $paragraph;
    }
683044
protected function sibling($node, $siblingDir = 'nextSibling')
    {
        $nodes = array();

        do {
            if ($node !== $this->getNode(0) && 1 === $node->nodeType) {
                $nodes[] = $node;
            }
        } while ($node = $node->$siblingDir);

        return $nodes;
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
1032288
protected function getFixableMethodAnnotations(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex): array
    {
        $tokens = $phpCsFile->getTokens();

        $path = $this->findBasePath($phpCsFile->getFilename());
        if (!$path) {
            // We cannot fix it then for now
            return [];
        }

        $annotations = [];
        for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) {
            if ($tokens[$i]['code'] !== T_DOC_COMMENT_TAG || $tokens[$i]['content'] !== '@method') {
                continue;
            }

            // T_DOC_COMMENT_STRING invalid, another sniff should check on this
            if (strpos($tokens[$i + 2]['content'], ' ') === false) {
                continue;
            }

            [$class, $method] = explode(' ', $tokens[$i + 2]['content'], 2);

            $ignoredMethods = [
                'getFactory()',
                'getConfig()',
                'getSharedConfig()',
                'getApplication()',
            ];
            if (in_array($method, $ignoredMethods, true)) {
                continue;
            }

            if (substr($class, -9) === 'Interface' || substr($class, 0, 5) === '\\Orm\\') {
                continue;
            }
            if (!preg_match('/^[A-Z]/', $class)) {
                continue;
            }
            if ($this->isAbstract($class)) {
                continue;
            }

            $interface = $class . 'Interface';
            $interfacePathElement = str_replace('\\', DIRECTORY_SEPARATOR, $interface);
            $interfacePath = $path . $interfacePathElement . '.php';

            if (!file_exists($interfacePath)) {
                $phpCsFile->addError(
                    sprintf('Interface missing for %s annotation of %s', $method, $class),
                    $i,
                    'Annotation.Interface.Missing'
                );
                continue;
            }

            $annotation = [
                'index' => $i,
                'method' => $method,
                'class' => $class,
                'interface' => $interface,
            ];

            $annotations[] = $annotation;
        }

        return $annotations;
    }