<commit_before><?php
namespace WoohooLabs\Yin\JsonApi\Schema;

use WoohooLabs\Yin\JsonApi\Exception\InclusionUnrecognized;
use WoohooLabs\Yin\JsonApi\Request\RequestInterface;

class Relationships
{
    /**
     * @var array
     */
    private $relationships;

    /**
     * @param array $relationships
     */
    public function __construct(array $relationships = [])
    {
        $this->relationships = $relationships;
    }

    /**
     * @param array $relationships
     */
    public function setRelationships(array $relationships)
    {
        $this->relationships = $relationships;
    }

    /**
     * @param string $name
     * @param \Closure $relationship
     */
    public function setRelationship($name, \Closure $relationship)
    {
        $this->relationships[$name] = $relationship;
    }

    /**
     * @param mixed $resource
     * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
     * @param \WoohooLabs\Yin\JsonApi\Schema\Included $included
     * @param string $resourceType
     * @param string $baseRelationshipPath
     * @return array
     */
    public function transform(
        $resource,
        RequestInterface $request,
        Included $included,
        $resourceType,
        $baseRelationshipPath
    ) {
        $relationships = [];

        $this->validateRelationships($request, $baseRelationshipPath, $relationships);

        foreach ($this->relationships as $relationshipName => $relationshipCallback) {
            $relationship = $this->transformRelationship(
                $relationshipName,
                $resource,
                $request,
                $included,
                $resourceType,
                $baseRelationshipPath
            );

            if ($relationship !== null) {
                $relationships[$relationshipName] = $relationship;
            }
        }

        return $relationships;
    }

    /**
     * @param string $relationshipName
     * @param mixed $resource
     * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
     * @param \WoohooLabs\Yin\JsonApi\Schema\Included $included<commit_msg>Fixed detection of non-existent relationships<commit_after><?php
namespace WoohooLabs\Yin\JsonApi\Schema;

use WoohooLabs\Yin\JsonApi\Exception\InclusionUnrecognized;
use WoohooLabs\Yin\JsonApi\Request\RequestInterface;

class Relationships
{
    /**
     * @var array
     */
    private $relationships;

    /**
     * @param array $relationships
     */
    public function __construct(array $relationships = [])
    {
        $this->relationships = $relationships;
    }

    /**
     * @param array $relationships
     */
    public function setRelationships(array $relationships)
    {
        $this->relationships = $relationships;
    }

    /**
     * @param string $name
     * @param \Closure $relationship
     */
    public function setRelationship($name, \Closure $relationship)
    {
        $this->relationships[$name] = $relationship;
    }

    /**
     * @param mixed $resource
     * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
     * @param \WoohooLabs\Yin\JsonApi\Schema\Included $included
     * @param string $resourceType
     * @param string $baseRelationshipPath
     * @return array
     */
    public function transform(
        $resource,
        RequestInterface $request,
        Included $included,
        $resourceType,
        $baseRelationshipPath
    ) {
        $relationships = [];

        $this->validateRelationships($request, $baseRelationshipPath, $this->relationships);

        foreach ($this->relationships as $relationshipName => $relationshipCallback) {
            $relationship = $this->transformRelationship(
                $relationshipName,
                $resource,
                $request,
                $included,
                $resourceType,
                $baseRelationshipPath
            );

            if ($relationship !== null) {
                $relationships[$relationshipName] = $relationship;
            }
        }

        return $relationships;
    }

    /**
     * @param string $relationshipName
     * @param mixed $resource
     * @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
     * @param \WoohooLabs\Yin\JsonApi\Schema\Included $included
{'fraction_non_alphanumeric': 0.10870577281191807, 'fraction_numerical': 0.0, 'mean_word_length': 2.2430188679245284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '1064847', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1170, 'n_words': 217}