<commit_before><?php

namespace spec\GrumPHP\Collection;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Finder\SplFileInfo;

class FilesCollectionSpec extends ObjectBehavior
{
    /**
     * @var string
     */
    protected $tempFile;

    function let(SplFileInfo $file1, SplFileInfo $file2)
    {
        $this->tempFile = tempnam(sys_get_temp_dir(), 'phpspec');
        $this->beConstructedWith(array($file1, $file2));
    }

    function letgo()
    {
        unlink($this->tempFile);
    }

    function it_is_initializable()
    {
        $this->shouldHaveType('GrumPHP\Collection\FilesCollection');
    }

    function it_is_an_array_collection()
    {
        $this->shouldHaveType('Doctrine\Common\Collections\ArrayCollection');
    }

    function it_should_filter_by_name(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getFilename()->willReturn('file.php');
        $file2->getFilename()->willReturn('file.png');

        $result = $this->name('*.php');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_not_name(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getFilename()->willReturn('file.php');
        $file2->getFilename()->willReturn('file.png');

        $result = $this->notName('*.png');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_path(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->path('path1');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_not_path(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->notPath('path2');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_size(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->isFile()->willReturn(true);
        $file2->isFile()->willReturn(true);
        $file1->getRealPath()->willReturn($this->tempFile);
        $file2->getRealPath()->willReturn($this->tempFile);
        $file1->getSize()->willReturn(8 * 1024);
        $file2->getSize()->willReturn(16 * 1024);

        $result = $this->size('>= 4K')->size('<= 10K');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->isFile()->willReturn(true);
        $file2->isFile()->willReturn(true);
        $file1->getRealPath()->willReturn($this->tempFile);
        $file2->getRealPath()->willReturn($this->tempFile);
        $file1->getMTime()->willReturn(strtotime('-4 hours'));
        $file2->getMTime()->willReturn(strtotime('-5 days'));

        $result = $this->date('since yesterday');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_callback(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->filter(function (SplFileInfo $file) {
            return $file->getRelativePathname() === 'path1/file.php';
        });
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_a_list_of_files(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getPathname()->willReturn('path1/file.php');
        $file2->getPathname()->willReturn('path2/file.php');

        $iterator = new \ArrayIterator([$file1->getWrappedObject()]);
        $result = $this->filterByFileList($iterator);
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }
}
<commit_msg>Fix PHP53<commit_after><?php

namespace spec\GrumPHP\Collection;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Finder\SplFileInfo;

class FilesCollectionSpec extends ObjectBehavior
{
    /**
     * @var string
     */
    protected $tempFile;

    function let(SplFileInfo $file1, SplFileInfo $file2)
    {
        $this->tempFile = tempnam(sys_get_temp_dir(), 'phpspec');
        $this->beConstructedWith(array($file1, $file2));
    }

    function letgo()
    {
        unlink($this->tempFile);
    }

    function it_is_initializable()
    {
        $this->shouldHaveType('GrumPHP\Collection\FilesCollection');
    }

    function it_is_an_array_collection()
    {
        $this->shouldHaveType('Doctrine\Common\Collections\ArrayCollection');
    }

    function it_should_filter_by_name(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getFilename()->willReturn('file.php');
        $file2->getFilename()->willReturn('file.png');

        $result = $this->name('*.php');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_not_name(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getFilename()->willReturn('file.php');
        $file2->getFilename()->willReturn('file.png');

        $result = $this->notName('*.png');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_path(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->path('path1');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_not_path(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->notPath('path2');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_size(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->isFile()->willReturn(true);
        $file2->isFile()->willReturn(true);
        $file1->getRealPath()->willReturn($this->tempFile);
        $file2->getRealPath()->willReturn($this->tempFile);
        $file1->getSize()->willReturn(8 * 1024);
        $file2->getSize()->willReturn(16 * 1024);

        $result = $this->size('>= 4K')->size('<= 10K');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->isFile()->willReturn(true);
        $file2->isFile()->willReturn(true);
        $file1->getRealPath()->willReturn($this->tempFile);
        $file2->getRealPath()->willReturn($this->tempFile);
        $file1->getMTime()->willReturn(strtotime('-4 hours'));
        $file2->getMTime()->willReturn(strtotime('-5 days'));

        $result = $this->date('since yesterday');
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_callback(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getRelativePathname()->willReturn('path1/file.php');
        $file2->getRelativePathname()->willReturn('path2/file.png');

        $result = $this->filter(function (SplFileInfo $file) {
            return $file->getRelativePathname() === 'path1/file.php';
        });
        $result->shouldBeAnInstanceOf('GrumPHP\Collection\FilesCollection');
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }

    function it_should_filter_by_a_list_of_files(SplFileInfo $file1, SplFileInfo $file2)
    {
        $file1->getPathname()->willReturn('path1/file.php');
        $file2->getPathname()->willReturn('path2/file.php');

        $iterator = new \ArrayIterator(array($file1->getWrappedObject()));
        $result = $this->filterByFileList($iterator);
        $result->count()->shouldBe(1);
        $files = $result->toArray();
        $files[0]->shouldBe($file1);
    }
}

{'fraction_non_alphanumeric': 0.17622576388183941, 'fraction_numerical': 0.01969343213886915, 'mean_word_length': 3.3134851138353767, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 219, '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': '2972259', 'n_tokens_mistral': 3196, 'n_tokens_neox': 3094, 'n_words': 341}