<commit_before><?php
/**
 * This file is part of Railt package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);

namespace Railt\Reflection\Base\Containers;

use Railt\Reflection\Contracts\Containers\HasArguments;
use Railt\Reflection\Contracts\Types\ArgumentType;

/**
 * Trait BaseArgumentsContainer
 * @mixin HasArguments
 */
trait BaseArgumentsContainer
{
    /**
     * @var array|ArgumentType[]
     */
    protected $arguments = [];

    /**
     * @return iterable|ArgumentType[]
     */
    public function getArguments(): iterable
    {
        return \array_values($this->resolve()->arguments);
    }

    /**
     * @param string $name
     * @return bool
     */
    public function hasArgument(string $name): bool
    {
        return \array_key_exists($name, $this->resolve()->arguments);
    }

    /**
     * @param string $name
     * @return null|ArgumentType
     */
    public function getArgument(string $name): ?ArgumentType
    {
        return $this->resolve()->arguments[$name] ?? null;
    }

    /**
     * @return int
     */
    public function getNumberOfArguments(): int
    {
        return \count($this->resolve()->arguments);
    }

    /**
     * @return int
     */
    public function getNumberOfRequiredArguments(): int
    {
        return (int)\array_reduce($this->resolve()->arguments, function (?int $carry, ArgumentType $argument): int {
            return (int)$carry + (int)! $argument->hasDefaultValue();
        });
    }

    /**
     * @return int
     */
    public function getNumberOfOptionalArguments(): int
    {
        return (int)\array_reduce($this->resolve()->arguments, function (?int $carry, ArgumentType $argument): int {
            return (int)$carry + (int)$argument->hasDefaultValue();
        });
    }
}<commit_msg>Improve behavior of optional and required argument methods<commit_after><?php
/**
 * This file is part of Railt package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);

namespace Railt\Reflection\Base\Containers;

use Railt\Reflection\Contracts\Containers\HasArguments;
use Railt\Reflection\Contracts\Types\ArgumentType;

/**
 * Trait BaseArgumentsContainer
 * @mixin HasArguments
 */
trait BaseArgumentsContainer
{
    /**
     * @var array|ArgumentType[]
     */
    protected $arguments = [];

    /**
     * @return iterable|ArgumentType[]
     */
    public function getArguments(): iterable
    {
        return \array_values($this->resolve()->arguments);
    }

    /**
     * @param string $name
     * @return bool
     */
    public function hasArgument(string $name): bool
    {
        return \array_key_exists($name, $this->resolve()->arguments);
    }

    /**
     * @param string $name
     * @return null|ArgumentType
     */
    public function getArgument(string $name): ?ArgumentType
    {
        return $this->resolve()->arguments[$name] ?? null;
    }

    /**
     * @return int
     */
    public function getNumberOfArguments(): int
    {
        return \count($this->resolve()->arguments);
    }

    /**
     * @return int
     */
    public function getNumberOfRequiredArguments(): int
    {
        return (int)\array_reduce($this->resolve()->arguments, [$this, 'requiredArgumentsCounter'], 0);
    }

    /**
     * @return int
     */
    public function getNumberOfOptionalArguments(): int
    {
        return (int)\array_reduce($this->resolve()->arguments, [$this, 'optionalArgumentsCounter'], 0);
    }

    /**
     * @param int $carry
     * @param ArgumentType $argument
     * @return int
     */
    private function optionalArgumentsCounter(int $carry, ArgumentType $argument): int
    {
        return $carry + (int)$argument->hasDefaultValue();
    }

    /**
     * @param int $carry
     * @param ArgumentType $argument
     * @return int
     */
    private function requiredArgumentsCounter(int $carry, ArgumentType $argument): int
    {
        return $carry + (int)! $argument->hasDefaultValue();
    }
}
{'fraction_non_alphanumeric': 0.13506368661379475, 'fraction_numerical': 0.0009613073780341264, 'mean_word_length': 2.6962699822380105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6888449', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1141, 'n_words': 273}