<commit_before><?php

namespace eCampApi;

use Laminas\ApiTools\Hal\Collection;
use Laminas\ApiTools\Hal\Entity;
use Laminas\ApiTools\Hal\Metadata\Metadata;
use Laminas\ApiTools\Hal\ResourceFactory;
use Laminas\Paginator\Paginator;
use Traversable;

class HalResourceFactory extends ResourceFactory {
    public function createEntityFromMetadata($object, Metadata $metadata, $renderEmbeddedEntities = true) {
        $halEntity = parent::createEntityFromMetadata($object, $metadata, $renderEmbeddedEntities);

        if ($halEntity instanceof Entity) {
            $entity = $halEntity->getEntity();
            if (!isset($entity->_hydrateInfo_)) {
                $hydrator = $metadata->getHydrator();

                if (method_exists($hydrator, 'HydrateInfo')) {
                    $entity->_hydrateInfo_ = call_user_func([$hydrator, 'HydrateInfo']);
                }
            }
        }

        return $halEntity;
    }

    /**
     * @param array|Paginator|Traversable $object
     */
    public function createCollectionFromMetadata($object, Metadata $metadata): Collection {
        $halCollection = parent::createCollectionFromMetadata($object, $metadata);

        $collection = $halCollection->getCollection();
        $entityRoute = $halCollection->getEntityRoute();
        $entityRouteParams = $halCollection->getEntityRouteParams();
        $entityRouteOptions = $halCollection->getEntityRouteOptions();
        $halCollection = new HalCollection($collection, $entityRoute, $entityRouteParams, $entityRouteOptions);

        if (isset($object->_hydrateInfo_)) {
            $halCollection->_hydrateInfo_ = $object->_hydrateInfo_;
        } else {
            $hydrator = $metadata->getHydrator();
            if (method_exists($hydrator, 'HydrateInfo')) {
                $halCollection->_hydrateInfo_ = call_user_func([$hydrator, 'HydrateInfo']);
            }<commit_msg>in php8 method_exists(NULL, .) throws an exception<commit_after><?php

namespace eCampApi;

use Laminas\ApiTools\Hal\Collection;
use Laminas\ApiTools\Hal\Entity;
use Laminas\ApiTools\Hal\Metadata\Metadata;
use Laminas\ApiTools\Hal\ResourceFactory;
use Laminas\Paginator\Paginator;
use Traversable;

class HalResourceFactory extends ResourceFactory {
    public function createEntityFromMetadata($object, Metadata $metadata, $renderEmbeddedEntities = true) {
        $halEntity = parent::createEntityFromMetadata($object, $metadata, $renderEmbeddedEntities);

        if ($halEntity instanceof Entity) {
            $entity = $halEntity->getEntity();
            if (!isset($entity->_hydrateInfo_)) {
                $hydrator = $metadata->getHydrator();
                if (null != $hydrator && method_exists($hydrator, 'HydrateInfo')) {
                    $entity->_hydrateInfo_ = call_user_func([$hydrator, 'HydrateInfo']);
                }
            }
        }

        return $halEntity;
    }

    /**
     * @param array|Paginator|Traversable $object
     */
    public function createCollectionFromMetadata($object, Metadata $metadata): Collection {
        $halCollection = parent::createCollectionFromMetadata($object, $metadata);

        $collection = $halCollection->getCollection();
        $entityRoute = $halCollection->getEntityRoute();
        $entityRouteParams = $halCollection->getEntityRouteParams();
        $entityRouteOptions = $halCollection->getEntityRouteOptions();
        $halCollection = new HalCollection($collection, $entityRoute, $entityRouteParams, $entityRouteOptions);

        if (isset($object->_hydrateInfo_)) {
            $halCollection->_hydrateInfo_ = $object->_hydrateInfo_;
        } else {
            $hydrator = $metadata->getHydrator();
            if (null != $hydrator && method_exists($hydrator, 'HydrateInfo')) {
                $halCollection->_hydrateInfo_ = call_user_func([$hydrator, 'HydrateInfo']);
            }
{'fraction_non_alphanumeric': 0.12028910686628808, 'fraction_numerical': 0.0002581311306143521, 'mean_word_length': 3.262926292629263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5155687', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1032, 'n_words': 183}