<commit_before><?php
namespace Redbox\Scan;
use Redbox\Scan\FileSystem\RecursiveDirectoryIterator as TestDirectoryIterator;


/**
 * Note just a draft POC atm ..
 *
 */

/**
 * Class Scan
 * @package Redbox\Scan
 */
class ScanService {

    /**
     * @var Adapter\AdapterInterface $adapter;
     */
    protected $adapter;

    public function __construct(Adapter\AdapterInterface $adapter = null)
    {
        if ($adapter)
            $this->adapter = $adapter;

    }

    /**
     * @return Adapter\AdapterInterface
     */
    public function getAdapter()
    {
        return $this->adapter;
    }


    // TODO: Write to collection
    // Todo: could throw exceptions for permission denied

    public function index($path = "", Adapter\AdapterInterface $adapter = null)
    {
        if (!$adapter) {
            if (!$this->getAdapter()) {
                throw new Exception\RuntimeException('An Adaptor must been set before calling index()');
            }
            $adapter = $this->getAdapter();
        }

        $report = new Report\Report();
        $report->setName('a scan');
        $report->setDate('Date');
        $report->setPath($path);

        // TODO: This should be the relative with to
        $activePath = $path;
        $items = array();

        $objects = new \RecursiveIteratorIterator(new TestDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($objects as $name => $object) {

            if ($object->getFilename() == '.' || $object->getFilename() == '..')
                continue;

            if ($object->isDir()) {
                $activePath = $object->getPathName();
                $items[$activePath] = array();
            } else {
                $items[$activePath][$object->getPathname()] = $object->getMD5Hash();
            }
        }
        $report->setItems($items);
        $adapter->write($report);
    }

    public function scan($path = "", Adapter\AdapterInterface $adapter = null)
    {
        if (!$adapter) {
            if (!$this->getAdapter()) {
                throw new Exception\RuntimeException('An Adaptor must been set before calling scan()');
            }
            $adapter = $this->getAdapter();
        }

        // Todo: could throw exceptions for permission denied
        $items = $adapter->read()['scan']['items'];

        foreach($items as $path => $files) {
            if ($path != './tmp') continue;

            $objects = new \RecursiveIteratorIterator(new TestDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($objects as $object) {
                if ($object->isFile() && isset($files[$object->getPathname()])) {
                    if ($files[$object->getPathname()] != $object->getMD5Hash())
                        echo('Veranderd: '.$object->getPathname())."\r\n";
                } elseif ($object->isFile() && !isset($files[$object->getPathname()])) {
                        echo 'Nieuw bestand: '.$object->getPathname()."\r\n";
                }
            }
        }
    }
}<commit_msg>Removed  argument from scan() and added braces to statements in ScanService.php<commit_after><?php
namespace Redbox\Scan;
use Redbox\Scan\FileSystem\RecursiveDirectoryIterator as TestDirectoryIterator;


/**
 * Note just a draft POC atm ..
 *
 */

/**
 * Class Scan
 * @package Redbox\Scan
 */
class ScanService {

    /**
     * @var Adapter\AdapterInterface $adapter;
     */
    protected $adapter;

    public function __construct(Adapter\AdapterInterface $adapter = null)
    {
        if ($adapter) {
            $this->adapter = $adapter;
        }

    }

    /**
     * @return Adapter\AdapterInterface
     */
    public function getAdapter()
    {
        return $this->adapter;
    }


    // TODO: Write to collection
    // Todo: could throw exceptions for permission denied

    public function index($path = "", Adapter\AdapterInterface $adapter = null)
    {
        if (!$adapter) {
            if (!$this->getAdapter()) {
                throw new Exception\RuntimeException('An Adaptor must been set before calling index()');
            }
            $adapter = $this->getAdapter();
        }

        $report = new Report\Report();
        $report->setName('a scan');
        $report->setDate('Date');
        $report->setPath($path);

        // TODO: This should be the relative with to
        $activePath = $path;
        $items = array();

        $objects = new \RecursiveIteratorIterator(new TestDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($objects as $name => $object) {

            if ($object->getFilename() == '.' || $object->getFilename() == '..') {
                continue;
            }

            if ($object->isDir()) {
                $activePath = $object->getPathName();
                $items[$activePath] = array();
            } else {
                $items[$activePath][$object->getPathname()] = $object->getMD5Hash();
            }
        }
        $report->setItems($items);
        $adapter->write($report);
    }

    public function scan(Adapter\AdapterInterface $adapter = null)
    {
        if (!$adapter) {
            if (!$this->getAdapter()) {
                throw new Exception\RuntimeException('An Adaptor must been set before calling scan()');
            }
            $adapter = $this->getAdapter();
        }

        // Todo: could throw exceptions for permission denied
        $items = $adapter->read()['scan']['items'];

        foreach($items as $path => $files) {
            if ($path != './tmp') continue;

            $objects = new \RecursiveIteratorIterator(new TestDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($objects as $object) {
                if ($object->isFile() && isset($files[$object->getPathname()])) {
                    if ($files[$object->getPathname()] != $object->getMD5Hash())
                        echo('Veranderd: '.$object->getPathname())."\r\n";
                } elseif ($object->isFile() && !isset($files[$object->getPathname()])) {
                        echo 'Nieuw bestand: '.$object->getPathname()."\r\n";
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.15011250401800064, 'fraction_numerical': 0.0006428801028608164, 'mean_word_length': 2.0150193798449614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '2087597', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1638, 'n_words': 369}