<commit_before><?php

namespace Spryker\Sniffs\Factory;

/**
 * Spryker Factory classes may not contain multiple object instantiations.
 */
class OneNewPerMethodSniff implements \PHP_CodeSniffer_Sniff
{

    /**
     * @inheritdoc
     */
    public function register()
    {
        return [
            T_FUNCTION,
        ];
    }

    /**
     * @inheritdoc
     */
    public function process(\PHP_CodeSniffer_File $phpCsFile, $stackPointer)
    {
        if ($this->isFactory($phpCsFile) && $this->hasMoreThenOneNewInMethod($phpCsFile, $stackPointer)) {
            $classMethod = $this->getClassMethod($phpCsFile, $stackPointer);
            $phpCsFile->addError(
                $classMethod . ' contains more then one new. Fix this by extract a method.',
                $stackPointer
            );
        }
    }

    /**
     * @param \PHP_CodeSniffer_File $phpCsFile
     *<commit_msg>Only check OneNewPerMethod for core factories.<commit_after><?php

namespace Spryker\Sniffs\Factory;

use Spryker\Sniffs\AbstractSniffs\AbstractSprykerSniff;

/**
 * Spryker Factory classes may not contain multiple object instantiations.
 */
class OneNewPerMethodSniff extends AbstractSprykerSniff
{

    /**
     * @inheritdoc
     */
    public function register()
    {
        return [
            T_FUNCTION,
        ];
    }

    /**
     * @inheritdoc
     */
    public function process(\PHP_CodeSniffer_File $phpCsFile, $stackPointer)
    {
        if ($this->isFactory($phpCsFile) && !$this->isCoreClass($phpCsFile) && $this->hasMoreThenOneNewInMethod($phpCsFile, $stackPointer)) {
            $classMethod = $this->getClassMethod($phpCsFile, $stackPointer);
            $phpCsFile->addError(
                $classMethod . ' contains more then one new. Fix this by extract a method.',
                $stackPointer
            );
        }
    }

    /**
     * @param \PHP_CodeSniffer_File $phpCsFile
     *
     * @return bool
     */
    protected function isCoreClass(\PHP_CodeSniffer_File $phpCsFile)
    {
        $namespace = $this->getNamespace($phpCsFile);

        return ($namespace === static::NAMESPACE_SPRYKER);
    }

    /**
     * @param \PHP_CodeSniffer_File $phpCsFile
     *
{'fraction_non_alphanumeric': 0.11297640653357532, 'fraction_numerical': 0.0, 'mean_word_length': 2.335854765506808, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '926441', 'n_tokens_mistral': 673, 'n_tokens_neox': 646, 'n_words': 126}