diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..67fa70d
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,37 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: "[BUG]"
+labels: bug
+assignees: vinogradsoft
+
+---
+
+
+
+What are the steps to reproduce this issue?
+-------------------------------------------
+1. …
+2. …
+3. …
+
+What happens?
+-------------
+…
+
+What were you expecting to happen?
+----------------------------------
+…
+
+Any logs, error output, etc?
+----------------------------
+
+…
+
+Any other comments?
+-------------------
+…
+
+What version you using?
+----------------------------------------
+…
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
index bbcbbe7..ff42776 100644
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -1,9 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
-title: ''
-labels: ''
-assignees: ''
+title: "[ENHANCEMENT]"
+labels: enhancement
+assignees: vinogradsoft
---
diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 330f6ff..c62f94a 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
+ php: [8.0, 8.1, 8.2, 8.3]
steps:
- uses: actions/checkout@v2
@@ -44,4 +44,9 @@ jobs:
run: composer run-script lint
- name: Run test suite
- run: vendor/bin/phpunit --coverage-clover=coverage.xml
\ No newline at end of file
+ run: vendor/bin/phpunit --coverage-clover=coverage.xml
+
+ - name: Upload coverage reports to Codecov
+ uses: codecov/codecov-action@v3
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
\ No newline at end of file
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index e63bfd4..4a2d101 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -60,7 +60,7 @@ representative at an online or offline event.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
-@xR2_D2x.
+admin@vinogradsoft.com.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2ad5592..4a8e0bc 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,9 +1,12 @@
-Thank you for contributing to this project.
-
-Please submit pull requests to the master branch only.
-
-Please run phpunit.
-
-If you have added something new, create a new unit test. If you have changed something, update all unit tests as necessary.
-
-We aim to achieve 100% code coverage by tests, including checking for PHP errors and exceptional situations. Therefore, make sure your new or modified tests fully cover all changes you have made.
+# Contributing
+
+Thanks for your contribution to this project.
+
+## Pull requests
++ If you added something new, create a new unit test. If you change anything, update everything if necessary
+ unit tests.
++ We strive to achieve 100% code coverage with tests, including checking for PHP errors and exceptions. That's why
+ Make sure your new or changed tests fully cover all the changes you've made.
++ Make sure you have updated `README.md`.
++ Create feature branches. Only submit pull requests to the master branch.
++ One pull request per feature.
diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..741cc8a
--- /dev/null
+++ b/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,44 @@
+# Pull Request Details
+
+
+
+## Description
+
+
+
+## Related Issue
+
+
+
+
+
+
+## Context
+
+
+
+## How Has This Been Tested
+
+
+
+
+
+## Types of changes
+
+
+
+- [ ] Docs change / refactoring / dependency upgrade
+- [ ] Bug fix (non-breaking change which fixes an issue)
+- [ ] New feature (non-breaking change which adds functionality)
+- [ ] Breaking change (fix or feature that would cause existing functionality to change)
+
+## Checklist
+
+
+
+
+- [ ] My change requires a change to the documentation.
+- [ ] I have updated the documentation accordingly.
+- [ ] I have read the **CONTRIBUTING** document.
+- [ ] I have added tests to cover my changes.
+- [ ] All new and existing tests passed.
\ No newline at end of file
diff --git a/README.md b/README.md
index cff18dd..ffdc219 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,332 @@
-# Scanner
+
+
+
+
-Библиотека для обхода деревьев.
+[![codecov](https://codecov.io/gh/vinogradsoft/scanner/graph/badge.svg?token=9KA3S2VXBQ)](https://codecov.io/gh/vinogradsoft/scanner)
+
-Установка
+
+
+# What is Scanner?
+
+> 👉 Scanner is a skeleton for building systems for searching and processing data in hierarchical structures. It offers
+> two approaches to data analysis: the first, breadth-first analysis, looks at all levels of the tree in one pass, and
+> the second, depth-first analysis, processes each level of the tree in turn, starting from the root. The main purpose
+> of this tool is to enable developers to focus on the logic of the application rather than how to traverse trees.
+> Scanner can be useful for programmers working with hierarchical data and seeking to automate the process of processing
+> such data.
+
+## Features
+
+- 💪 Support for different drivers for different use cases (for
+ example, [file driver](https://github.com/vinogradsoft/files-driver) for directory traversal or ArrayDriver for
+ working with arrays).
+- 👍 Ability to search and process certain elements in tree structures.
+- 🚧 Filtering elements at the time of crawling.
+- 🤚 Stop tree traversal at any location based on condition.
+- ⚗️ Flexibility of use thanks to its own configurations and parameters.
+
+Install
---------
-Предпочтительный способ установки - через [composer](http://getcomposer.org/download/).
+To install with composer:
+
+```
+php composer require vinogradsoft/scanner "^2.0"
+```
+
+## General Information
+
+The main object in the library is `Vinograd\Scanner\Scanner`. This object accumulates all the traversal settings and
+starts traversing the tree.
+
+Bypass algorithms are placed in separate classes, so-called strategies, which can be changed depending on the task.
+There are two such strategies implemented in the library: breadth-first (`Vinograd\Scanner\BreadthStrategy`) and
+depth-first (`Vinograd\Scanner\SingleStrategy`).
+
+The `Vinograd\Scanner\Visitor` interface is used to process and collect data. There is no implementation for it in the
+library; its implementation is carried out by the developer using this library. There are 4 useful methods in this
+interface:
+
+- `scanStarted` - called when scanning starts;
+- `scanCompleted` - called when the strategy has completed its work;
+- `visitLeaf` - called when the strategy visited a leaf of the tree;
+- `visitNode` - called when the strategy visited a tree node;
+
+The depth-first traversal algorithm is achieved by the `Vinograd\Scanner\SingleStrategy` strategy. Its algorithm is
+quite simple. It receives the children of the node passed to it and exits. The idea is to put a `Scanner` in a `Visitor`
+and run the scan repeatedly for each child node in the `visitNode` method. The result is a controlled depth-first
+recursive traversal.
+
+In the `Vinograd\Scanner\BreadthStrategy` strategy there is no need to do this; it ends when the last element of the
+tree is reached.
+
+Among other things, the `\Vinograd\Scanner\Verifier` object is used during the crawl. Its purpose is to ensure that the
+child element meets the requirements and the `visitLeaf` and `visitNode` methods of the `Visitor` object should be
+called on the element. In other words, you can provide it with some rules and filter out the elements of the tree. For
+the `Vinograd\Scanner\BreadthStrategy` strategy, this does not mean that if a node is filtered, the strategy will not
+bypass its child nodes. This means that the `visitLeaf` and `visitNode` methods will not be called on failed elements.
+This way, you can configure the bypass to only perform processing on the target nodes. For
+the `Vinograd\Scanner\SingleStrategy` strategy this will mean that child nodes will not be scanned, since
+the `visitNode` method will not be called and you will not be able to run a scan for it. You can get around this by
+relaxing the rules in the `Verifier` object and creating a `Visitor` proxy, which runs a scan for all nodes, but does
+not call the `visitNode` method on the proxied object.
+
+The driver allows you to select the type of tree objects that need to be traversed. The library implements a driver for
+traversing arrays. The class is called `Vinograd\Scanner\ArrayDriver`. Another external
+implementation [files-driver](https://github.com/vinogradsoft/files-driver) allows you to traverse directories in the
+file system. Both of these drivers implement the `Vinograd\Scanner\Driver` interface.
+
+## Example
+
+Let's look at a conceptual use case.
+
+> 📢 To make the example clearer, it does not include checks that are typically performed in code. Instead, the example
+> focuses on demonstrating the capabilities of the system. The example includes a look at the classes that are needed to
+> understand how the system works. You can run the example by cloning
+> this [repository](https://github.com/vinogradsoft/example-for-scanner).
+
+### Formulation of the problem
+
+You need to make a console command that triggers a series of commands to be executed in a certain sequence, based on the
+configuration. In the configuration, you need to bypass the nodes, starting with `tasks`, and ignore the `other` node.
+
+The configuration looks like this:
+
+```php
+ [
+ 'make breakfast' => [
+ 'sandwich' => [
+ 'cut a piece of bread' => [
+ 'take the knife in your right hand',
+ 'cut a piece of bread on a wooden board'
+ ],
+ 'spread butter on bread',
+ 'put a piece of cheese on top',
+ ],
+ 'coffee' => [
+ 'take a cup',
+ 'pour coffee into a cup',
+ ],
+ ]
+ ],
+ 'other' => [
+ 'setting1' => 'value1',
+ 'setting2' => 'value2',
+ 'setting3' => 'value3'
+ ]
+];
+```
+
+A node is an array value of type `array`. A leaf is an array value of type `string`.
+Each leaf of the tree is a command that we will execute.
+
+### Implementation
+
+> ❗️ To simplify the demo code, we will run `echo`, in other words we will display the names of the nodes and the value of
+> the leaves.
+
+Let's write a handler and call it `Handler`. This class implements the `Vinograd\Scanner\Visitor` interface; it is in it
+that the names of nodes and the values of tree leaves will be output to the console.
+
+Code:
+
+```php
+handler = $handler;
+ $this->scanner = $scanner;
+ }
+
+ public function scanStarted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void
+ {
+ $this->handler->scanStarted($scanStrategy, $detect);
+ }
+
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void
+ {
+ $this->handler->scanCompleted($scanStrategy, $detect);
+ }
+
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentElement, mixed $data = null): void
+ {
+ $this->handler->visitLeaf($scanStrategy, $parentNode, $currentElement);
+ }
+
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentNode, mixed $data = null): void
+ {
+ $name = array_key_first($currentNode);
+ if ($name !== 'tasks') {
+ $this->handler->visitNode($scanStrategy, $parentNode, $currentNode);
+ }
+ $this->scanner->traverse($currentNode[$name]);
+ }
+}
```
-php composer require vinogradsoft/scanner "^1.0"
+
+In this code, we are most interested in the `visitNode` method, since it contains the logic for depth-first tree
+traversal. Since we don't want to print the name of the `tasks` node, we won't call our handler method if the node name
+is `tasks`. At the same time, we call the `traverse` method on the Scanner to go further into the tree.
+
+Let's write a filter that will allow us not to scan the `other` node from the configuration.
+
+Code:
+
+```php
+setDriver(new ArrayDriver());
+ $scanner->setVisitor(new ProxyHandler(new Handler(), $scanner));
+ $scanner->setStrategy(new SingleStrategy());
+ $scanner->addNodeFilter(new FilterForNodeOther());
+ $scanner->traverse($config);
+ }
+}
```
-"vinogradsoft/scanner": "^1.0"
+
+We complete the Scanner object with the objects necessary for the task and start traversing the tree nodes.
+
+On this line we create a new instance of the Scanner object:
+
+```php
+$scanner = new Scanner();
```
+
+Next, install the driver for working with arrays:
+
+```php
+$scanner->setDriver(new ArrayDriver());
+```
+
+The next step is to install `ProxyHandler`, passing our handler and `Scanner` to it in the constructor. We complete this
+stage by setting up a strategy for depth-first traversal.
+
+Code:
+
+```php
+$scanner->setVisitor(new ProxyHandler(new Handler(), $scanner));
+$scanner->setStrategy(new SingleStrategy());
+```
+
+In these lines:
+
+```php
+$scanner->addNodeFilter(new FilterForNodeOther());
+$scanner->traverse($config);
+```
+
+We add a filter that allows us not to scan the `other` node and start crawling the nodes.
+
+## Where is it used?
+
+Scanner is used in:
+
+- [File-search](https://github.com/vinogradsoft/file-search) - a library that allows you to search for the necessary
+ files and do something with them;
+- [Reflection](https://github.com/vinogradsoft/reflection) - a library that creates an object model of the specified
+ directory and allows you to manipulate it: copy, modify files, delete, move and create new ones.
+
+---
+
+⭐️ **Please leave a star if you find the project useful!**
+
+## Testing
+
+``` php composer tests ```
+
+## Contributing
+
+Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
+
+## License
+
+The MIT License (MIT). Please see License [File](LICENSE) for more information.
diff --git a/README_ru_RU.md b/README_ru_RU.md
new file mode 100644
index 0000000..fdb2025
--- /dev/null
+++ b/README_ru_RU.md
@@ -0,0 +1,335 @@
+
+
+
+
+
+[![codecov](https://codecov.io/gh/vinogradsoft/scanner/graph/badge.svg?token=9KA3S2VXBQ)](https://codecov.io/gh/vinogradsoft/scanner)
+
+
+
+
+# Что такое Scanner?
+
+> 👉 Scanner - это каркас для построения систем поиска и обработки данных в иерархических структурах. Он предлагает
+> два подхода к анализу данных: первый, анализ “в ширину”, просматривает все уровни дерева за один проход, а второй,
+> анализ “вглубь”, обрабатывает каждый уровень дерева по очереди, начиная с корня. Основная цель этого инструмента -
+> предоставить возможность разработчикам концентрироваться на логике приложения, а не том, как обходить деревья. Scanner
+> может быть полезен для программистов, работающих с иерархическими данными и стремящихся автоматизировать процесс
+> обработки таких данных.
+
+## Особенности библиотеки:
+
+- 💪 Поддержка различных драйверов для разных сценариев использования (например,
+ [файловый драйвер](https://github.com/vinogradsoft/files-driver) для обхода директорий или ArrayDriver для работы с
+ массивами).
+- 👍 Возможность поиска и обработки определённых элементов в древовидных структурах.
+- 🚧 Фильтрация элементов в моменте обхода.
+- 🤚 Остановка обхода дерева в любом месте по условию.
+- ⚗️ Гибкость использования благодаря своим собственным конфигурациям и параметрам.
+
+Установка
+---------
+
+Предпочтительный способ установки - через [composer](http://getcomposer.org/download/).
+
+Запустите команду
+
+```
+php composer require vinogradsoft/scanner "^2.0"
+```
+
+## Общая информация
+
+Основным объектом в библиотеке является `Vinograd\Scanner\Scanner`. Этот объект аккумулирует в себе все настройки обхода
+и запускает обход дерева.
+
+Алгоритмы обхода вынесены в отдельные классы, так называемые стратегии, которые можно менять в зависимости от задачи.
+Таких стратегий в библиотеке реализовано две: в ширину (`Vinograd\Scanner\BreadthStrategy`) и в
+глубину (`Vinograd\Scanner\SingleStrategy`).
+
+Для обработки и сбора данных используется интерфейс `Vinograd\Scanner\Visitor`. В библиотеке нет для него реализации,
+его реализацией занимается разработчик, использующий эту библиотеку. В этом интерфейсе 4 полезных метода:
+
+- `scanStarted` - вызывается, когда стартует обход;
+- `scanCompleted` - вызывается, когда стратегия завершила свою работу;
+- `visitLeaf` - вызывается, когда стратегия посетила лист дерева;
+- `visitNode` - вызывается, когда стратегия посетила узел дерева;
+
+Алгоритм обхода в глубину достигается стратегией `Vinograd\Scanner\SingleStrategy`. Ее алгоритм довольно прост. Она
+получает дочерние элементы переданного ей узла и завершается. Идея в том, чтобы поместить `Scanner` в `Visitor`
+и запускать сканирование повторно для каждого дочернего узла в методе `visitNode`. В итоге получится контролируемый
+рекурсивный обход в глубину.
+
+В стратегии `Vinograd\Scanner\BreadthStrategy` так делать не нужно, она завершается, когда будет достигнут последний
+элемент дерева.
+
+Кроме прочего, в моменте обхода используется объект `\Vinograd\Scanner\Verifier`. Его целью является достижение гарантии
+того, что дочерний элемент соответствует требованиям, и для элемента следует вызывать методы `visitLeaf` и `visitNode`
+объекта `Visitor`. Другими словами, его можно снабдить некоторыми правилами и отфильтровать элементы дерева. Для
+стратегии `Vinograd\Scanner\BreadthStrategy` это не означает, что если узел отфильтрован, обходить его дочерние узлы
+стратегия не будет. Это означает, что методы `visitLeaf` и `visitNode` не будут вызваны для не прошедших проверку
+элементов. Таким образом, можно настроить обход так, чтобы обработка выполнялась только на целевых узлах. Для
+стратегии `Vinograd\Scanner\SingleStrategy` это будет означать, что дочерние узлы просканированы не будут, так как
+метод `visitNode` не будет вызван, и вы не сможете запустить сканирование для него. Обойти это можно, смягчив правила в
+объекте `Verifier` и создав прокси `Visitor`, в котором запускать сканирование для всех узлов, но не вызывать
+метод `visitNode` у проксируемого объекта.
+
+Драйвер позволяет выбирать тип объектов дерева, которые нужно обходить. В библиотеке реализован драйвер для обхода
+массивов. Класс называется `Vinograd\Scanner\ArrayDriver`. Еще одна внешняя
+реализация [files-driver](https://github.com/vinogradsoft/files-driver) позволяет делать обход директорий в файловой
+системе. Оба этих драйвера реализуют интерфейс `Vinograd\Scanner\Driver`.
+
+## Пример
+
+Рассмотрим концептуальный пример использования.
+
+> 📢 Чтобы сделать пример более понятными, в нем не включены проверки, которые обычно выполняются в коде. Вместо этого
+> пример фокусируется на демонстрации возможностей системы. Пример включает в себя рассмотрение классов, которые нужны
+> для понимания работы системы. Запустить пример можно, клонировав себе
+> этот [репозиторий](https://github.com/vinogradsoft/example-for-scanner).
+
+### Постановка задачи
+
+Требуется сделать консольную команду, которая запускает выполнение в определенной последовательности ряд команд,
+основываясь на конфигурации. В конфигурации нужно обойти узлы, начиная с `tasks`, а узел `other` игнорировать.
+
+Конфигурация выглядит так:
+
+```php
+ [
+ 'сделать завтрак' => [
+ 'бутерброд' => [
+ 'отрезать кусок хлеба' => [
+ 'взять нож в правую руку',
+ 'отрезать на деревянной доске кусок хлеба'
+ ],
+ 'намазать хлеб маслом',
+ 'положить сверху кусок сыра',
+ ],
+ 'кофе' => [
+ 'взять чашку',
+ 'налить кофе в чашку',
+ ],
+ ]
+ ],
+ 'other' => [
+ 'setting1' => 'value1',
+ 'setting2' => 'value2',
+ 'setting3' => 'value3'
+ ]
+];
+```
+
+Узлом является значение массива с типом `array`. Листом считается значение массива с типом `string`.
+Каждый лист дерева - это команда, которую будем выполнять.
+
+### Реализация
+
+> ❗️ Для простоты демонстрационного кода запускать мы будем `echo`, другими словами будем выводить названия узлов и
+> значение листьев.
+
+Напишем обработчик и назовем его `Handler`. Этот класс реализует интерфейс `Vinograd\Scanner\Visitor`, именно в нем
+будут выводиться в консоль название узлов и значения листьев дерева.
+
+Код:
+
+```php
+handler = $handler;
+ $this->scanner = $scanner;
+ }
+
+ public function scanStarted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void
+ {
+ $this->handler->scanStarted($scanStrategy, $detect);
+ }
+
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void
+ {
+ $this->handler->scanCompleted($scanStrategy, $detect);
+ }
+
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentElement, mixed $data = null): void
+ {
+ $this->handler->visitLeaf($scanStrategy, $parentNode, $currentElement);
+ }
+
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentNode, mixed $data = null): void
+ {
+ $name = array_key_first($currentNode);
+ if ($name !== 'tasks') {
+ $this->handler->visitNode($scanStrategy, $parentNode, $currentNode);
+ }
+ $this->scanner->traverse($currentNode[$name]);
+ }
+}
+```
+
+В этом коде больше всего нас интересует метод `visitNode`, поскольку в нем и есть логика обхода дерева в глубину.
+Так как нам не хочется выводить название ноды `tasks`, мы не будем вызывать метод нашего обработчика, если название ноды
+равно `tasks`. При этом мы вызываем метод `traverse` у Scanner-а, чтобы пройти дальше вглубь дерева.
+
+Напишем фильтр, который нам позволит не сканировать узел `other` из конфигурации.
+
+Код:
+
+```php
+setDriver(new ArrayDriver());
+ $scanner->setVisitor(new ProxyHandler(new Handler(), $scanner));
+ $scanner->setStrategy(new SingleStrategy());
+ $scanner->addNodeFilter(new FilterForNodeOther());
+ $scanner->traverse($config);
+ }
+}
+```
+
+Комплектуем объект Scanner нужными для задачи объектами и запускаем обход узлов дерева.
+
+В этой строке мы создаем новый экземпляр объекта Scanner:
+
+```php
+$scanner = new Scanner();
+```
+
+Далее устанавливаем драйвер для работы с массивами:
+
+```php
+$scanner->setDriver(new ArrayDriver());
+```
+
+Следующим этапом устанавливаем `ProxyHandler`, передав ему в конструктор наш обработчик и `Scanner`. Завершаем этот
+этап установкой стратегии для обхода в глубину.
+
+Код:
+
+```php
+$scanner->setVisitor(new ProxyHandler(new Handler(), $scanner));
+$scanner->setStrategy(new SingleStrategy());
+```
+
+В этих строках:
+
+```php
+$scanner->addNodeFilter(new FilterForNodeOther());
+$scanner->traverse($config);
+```
+
+Добавляем фильтр, который позволяет не сканировать узел `other` и запускаем обход узлов.
+
+## Где используется?
+
+Scanner используется в:
+
+- [File-search](https://github.com/vinogradsoft/file-search) - библиотека, которая позволяет искать нужные файлы и
+ что-то с ними делать;
+- [Reflection](https://github.com/vinogradsoft/reflection) - библиотека, которая создает объектную модель указанной
+ директории и позволяет манипулировать ею: копировать, модифицировать файлы, удалять, перемещать и создавать новые.
+
+---
+
+⭐️ **Поставьте звездочку, если находите проект полезным!**
+
+## Тестировать
+
+```
+ php composer tests
+```
+
+## Содействие
+
+Пожалуйста, смотрите [ВКЛАД](CONTRIBUTING.md) для получения подробной информации.
+
+## Лицензия
+
+Лицензия MIT (MIT). Пожалуйста, смотрите [файл лицензии](LICENSE) для получения дополнительной информации.
\ No newline at end of file
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..e0f2e67
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,9 @@
+# Reporting security issues
+
+We value the contributions of the security research community.
+
+## Where should I report security issues?
+
+It is strongly recommended that you report all security issues privately via our email
+sec@vinogradsoft.com rather than via GitHub. Please provide relevant technical details and reproduction steps to
+expedite the investigation.
\ No newline at end of file
diff --git a/banner.svg b/banner.svg
new file mode 100644
index 0000000..0a564af
--- /dev/null
+++ b/banner.svg
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index 67a9ffc..45046a4 100644
--- a/composer.json
+++ b/composer.json
@@ -1,14 +1,23 @@
{
"name": "vinogradsoft/scanner",
- "description": "Tree Traversal Library.",
+ "description": "Vinograd is a powerful library for processing hierarchical data. It provides an intuitive API for traversing trees in breadth-first and depth-first orders. Developers can also implement their own visitor patterns to process specific nodes or leaves. ",
"license": "MIT",
+ "keywords": [
+ "Vinograd Scanner",
+ "Btree scanner",
+ "Data scanner",
+ "Tree scanner",
+ "Breadth first scanner",
+ "Depth first scanner"
+ ],
"authors": [
{
- "name": "vinograd",
- "email": "cmk.cmyk@mail.ru"
+ "name": "Grigor",
+ "email": "cmk.cmyk@mail.ru",
+ "role": "Founder and project lead"
}
],
- "version": "1.0.2",
+ "version": "2.0.0",
"minimum-stability": "stable",
"autoload": {
"psr-4": {
@@ -23,10 +32,10 @@
}
},
"require": {
- "php": ">=7.2"
+ "php": ">=8.0"
},
"require-dev": {
- "phpunit/phpunit": "^8.5",
+ "phpunit/phpunit": "^9.6",
"overtrue/phplint": "^2.0"
},
"repositories": [
diff --git a/src/AbstractChecker.php b/src/AbstractChecker.php
index 92af15f..c8303bc 100644
--- a/src/AbstractChecker.php
+++ b/src/AbstractChecker.php
@@ -5,8 +5,8 @@
abstract class AbstractChecker implements Checker
{
- /** @var Checker|null */
- protected $next = null;
+
+ protected Checker|null $next = null;
/**
* @param Checker $checker
@@ -19,13 +19,13 @@ public function append(Checker $checker): Checker
}
/**
- * @param $node
+ * @param mixed $element
* @return bool
*/
- public function can($node): bool
+ public function can(mixed $element): bool
{
if ($this->next !== null) {
- return $this->next->can($node);
+ return $this->next->can($element);
}
return true;
}
diff --git a/src/AbstractTraversalStrategy.php b/src/AbstractTraversalStrategy.php
index 4046ca4..4611fa0 100644
--- a/src/AbstractTraversalStrategy.php
+++ b/src/AbstractTraversalStrategy.php
@@ -6,24 +6,22 @@
abstract class AbstractTraversalStrategy
{
- /** @var bool */
- protected $stop = false;
+ protected bool $stop = false;
/**
- * @param mixed $detect
+ * @param mixed $node
* @param Driver $driver
- * @param NodeFactory $nodeFactory
* @param Verifier $leafVerifier
* @param Verifier $nodeVerifier
* @param Visitor $visitor
+ * @return void
*/
abstract public function detect(
- $detect,
- Driver $driver,
- NodeFactory $nodeFactory,
+ mixed $node,
+ Driver $driver,
Verifier $leafVerifier,
Verifier $nodeVerifier,
- Visitor $visitor
+ Visitor $visitor
): void;
/**
diff --git a/src/ArrayDriver.php b/src/ArrayDriver.php
index 8075bd7..15f768e 100644
--- a/src/ArrayDriver.php
+++ b/src/ArrayDriver.php
@@ -6,11 +6,9 @@
class ArrayDriver implements Driver
{
- /** @var array */
- private $dataForFilter;
+ private array|null $dataForFilter = null;
- /** @var array */
- private $next;
+ private array|null $next = null;
/**
* @param array $detect
@@ -37,10 +35,9 @@ public function isLeaf($found): bool
}
/**
- * @param array|mixed $source
- * @return array
+ * @inheritDoc
*/
- public function normalise($source)
+ public function normalize(mixed $source): array
{
if (!is_array($source)) {
return [$source];
@@ -51,7 +48,7 @@ public function normalise($source)
/**
* @return array
*/
- public function getDataForFilter()
+ public function getDataForFilter(): array
{
return $this->dataForFilter;
}
@@ -72,7 +69,7 @@ public function parse($source): array
}
/**
- *
+ * @return void
*/
public function beforeSearch(): void
{
@@ -82,8 +79,9 @@ public function beforeSearch(): void
/**
* @return array
*/
- public function next()
+ public function next(): array
{
return $this->next;
}
+
}
\ No newline at end of file
diff --git a/src/BaseChecker.php b/src/BaseChecker.php
index ea5be12..0f593f6 100644
--- a/src/BaseChecker.php
+++ b/src/BaseChecker.php
@@ -5,11 +5,10 @@
class BaseChecker extends AbstractChecker
{
- /** @var Filter */
- private $filter;
+
+ private Filter $filter;
/**
- * BaseChecker constructor.
* @param Filter $filter
*/
public function __construct(Filter $filter)
@@ -18,12 +17,12 @@ public function __construct(Filter $filter)
}
/**
- * @param $node
+ * @param mixed $element
* @return bool
*/
- public function can($node): bool
+ public function can(mixed $element): bool
{
- return $this->filter->filter($node) ? parent::can($node) : false;
+ return $this->filter->filter($element) ? parent::can($element) : false;
}
}
\ No newline at end of file
diff --git a/src/BreadthStrategy.php b/src/BreadthStrategy.php
index b7907ed..87cf945 100644
--- a/src/BreadthStrategy.php
+++ b/src/BreadthStrategy.php
@@ -7,21 +7,20 @@
class BreadthStrategy extends AbstractTraversalStrategy
{
+
/**
- * @param mixed $detect
+ * @param mixed $node
* @param Driver $driver
- * @param NodeFactory $nodeFactory
* @param Verifier $leafVerifier
* @param Verifier $nodeVerifier
* @param Visitor $visitor
*/
public function detect(
- $detect,
- Driver $driver,
- NodeFactory $nodeFactory,
- Verifier $leafVerifier,
- Verifier $nodeVerifier,
- Visitor $visitor
+ mixed $node,
+ Driver $driver,
+ Verifier $leafVerifier,
+ Verifier $nodeVerifier,
+ Visitor $visitor
): void
{
if ($this->stop) {
@@ -29,37 +28,37 @@ public function detect(
}
$queue = new SplQueue();
- $queue->enqueue($detect);
+ $queue->enqueue($node);
$completeFound = null;
- $visitor->scanStarted($this, $detect);
+ $visitor->scanStarted($this, $node);
while ($queue->count() > 0) {
- $completeFound = $node = $queue->dequeue();
- $founds = $driver->parse($node);
+ $completeFound = $element = $queue->dequeue();
+ $founds = $driver->parse($element);
- $driver->setDetect($node);
+ $driver->setDetect($element);
- foreach ($founds as $key => $found) {
+ foreach ($founds as $found) {
if ($this->stop) {
- $visitor->scanCompleted($this, $nodeFactory, $node);
+ $visitor->scanCompleted($this, $element);
return;
}
if ($driver->isLeaf($found)) {
if ($leafVerifier->can($driver->getDataForFilter())) {
- $visitor->visitLeaf($this, $nodeFactory, $node, $found);
+ $visitor->visitLeaf($this, $element, $found);
}
} else {
if ($nodeVerifier->can($driver->getDataForFilter())) {
- $visitor->visitNode($this, $nodeFactory, $node, $found);
+ $visitor->visitNode($this, $element, $found);
}
$queue->enqueue($driver->next());
}
}
}
- $visitor->scanCompleted($this, $nodeFactory, $completeFound);
+ $visitor->scanCompleted($this, $completeFound);
}
}
\ No newline at end of file
diff --git a/src/Checker.php b/src/Checker.php
index 33f785d..77f0781 100644
--- a/src/Checker.php
+++ b/src/Checker.php
@@ -5,6 +5,7 @@
interface Checker
{
+
/**
* @param Checker $checker
* @return Checker
@@ -12,8 +13,9 @@ interface Checker
public function append(Checker $checker): Checker;
/**
- * @param $found
+ * @param mixed $element
* @return bool
*/
- public function can($found): bool;
+ public function can(mixed $element): bool;
+
}
\ No newline at end of file
diff --git a/src/Driver.php b/src/Driver.php
index d2b0eef..485b2b4 100644
--- a/src/Driver.php
+++ b/src/Driver.php
@@ -5,41 +5,44 @@
interface Driver
{
+
/**
- * @param $source
+ * @param mixed $source
* @return array
*/
- public function parse($source): array;
+ public function parse(mixed $source): array;
/**
- * @param $source
+ * @param mixed $source
* @return mixed
*/
- public function normalise($source);
+ public function normalize(mixed $source): mixed;
/**
- * @param $detect
+ * @param mixed $detect
+ * @return void
*/
- public function setDetect($detect): void;
+ public function setDetect(mixed $detect): void;
/**
- * @param $found
+ * @param mixed $found
* @return bool
*/
- public function isLeaf($found): bool;
+ public function isLeaf(mixed $found): bool;
/**
* @return mixed
*/
- public function getDataForFilter();
+ public function getDataForFilter(): mixed;
/**
* @return mixed
*/
- public function next();
+ public function next(): mixed;
/**
- *
+ * @return void
*/
public function beforeSearch(): void;
+
}
\ No newline at end of file
diff --git a/src/Filter.php b/src/Filter.php
index 4302a1d..efcc5fa 100644
--- a/src/Filter.php
+++ b/src/Filter.php
@@ -5,14 +5,11 @@
interface Filter
{
+
/**
- * @param $found
+ * @param mixed $element
* @return bool
*/
- public function filter($found): bool;
+ public function filter(mixed $element): bool;
- /**
- * @param $config
- */
- public function setConfiguration($config): void;
}
\ No newline at end of file
diff --git a/src/Leaf.php b/src/Leaf.php
deleted file mode 100644
index 03b2ff2..0000000
--- a/src/Leaf.php
+++ /dev/null
@@ -1,9 +0,0 @@
-validate();
$this->driver->beforeSearch();
- $this->detect($source);
+ $this->detect($rootNode);
}
/**
- * Tool validation
+ * @return void
*/
protected function validate(): void
{
@@ -56,38 +49,21 @@ protected function validate(): void
if (empty($this->visitor)) {
throw new ConfigurationException('Visitor not installed.');
}
- if (empty($this->nodeFactory)) {
- throw new ConfigurationException('NodeFactory not installed.');
- }
- }
-
- /**
- * @param $detect
- */
- protected function detect($detect): void
- {
- $detect = $this->driver->normalise($detect);
- $this->traversal->detect($detect, $this->driver, $this->nodeFactory, $this->leafVerifier, $this->nodeVerifier, $this->visitor);
- }
-
- /**
- * @return NodeFactory
- */
- public function getNodeFactory(): NodeFactory
- {
- return $this->nodeFactory;
}
/**
- * @param NodeFactory $nodeFactory
+ * @param mixed $detect
+ * @return void
*/
- public function setNodeFactory(NodeFactory $nodeFactory): void
+ protected function detect(mixed $detect): void
{
- $this->nodeFactory = $nodeFactory;
+ $detect = $this->driver->normalize($detect);
+ $this->traversal->detect($detect, $this->driver, $this->leafVerifier, $this->nodeVerifier, $this->visitor);
}
/**
* @param AbstractTraversalStrategy $strategy
+ * @return void
*/
public function setStrategy(AbstractTraversalStrategy $strategy): void
{
@@ -107,6 +83,7 @@ public function getStrategy(): ?AbstractTraversalStrategy
/**
* @param Visitor $visitor
+ * @return void
*/
public function setVisitor(Visitor $visitor): void
{
@@ -117,18 +94,24 @@ public function setVisitor(Visitor $visitor): void
}
/**
- * @return Visitor
+ * @return Visitor|null
*/
public function getVisitor(): ?Visitor
{
return $this->visitor;
}
+ /**
+ * @return void
+ */
public function resetLeafFilters(): void
{
$this->leafVerifier->clear();
}
+ /**
+ * @return void
+ */
public function resetNodeFilters(): void
{
$this->nodeVerifier->clear();
@@ -136,6 +119,7 @@ public function resetNodeFilters(): void
/**
* @param Filter $filter
+ * @return void
*/
public function addLeafFilter(Filter $filter): void
{
@@ -144,6 +128,7 @@ public function addLeafFilter(Filter $filter): void
/**
* @param Filter $filter
+ * @return void
*/
public function addNodeFilter(Filter $filter): void
{
@@ -160,6 +145,7 @@ public function getDriver(): Driver
/**
* @param Driver $driver
+ * @return void
*/
public function setDriver(Driver $driver): void
{
diff --git a/src/SingleStrategy.php b/src/SingleStrategy.php
index 1b8c132..b61b866 100644
--- a/src/SingleStrategy.php
+++ b/src/SingleStrategy.php
@@ -5,48 +5,47 @@
class SingleStrategy extends AbstractTraversalStrategy
{
+
/**
- * @param mixed $detect
+ * @param mixed $node
* @param Driver $driver
- * @param NodeFactory $nodeFactory
* @param Verifier $leafVerifier
* @param Verifier $nodeVerifier
* @param Visitor $visitor
*/
public function detect(
- $detect,
- Driver $driver,
- NodeFactory $nodeFactory,
+ mixed $node,
+ Driver $driver,
Verifier $leafVerifier,
Verifier $nodeVerifier,
- Visitor $visitor
+ Visitor $visitor
): void
{
if ($this->stop) {
return;
}
- $visitor->scanStarted($this, $detect);
+ $visitor->scanStarted($this, $node);
- $founds = $driver->parse($detect);
- $driver->setDetect($detect);
+ $founds = $driver->parse($node);
+ $driver->setDetect($node);
foreach ($founds as $found) {
if ($this->stop) {
- $visitor->scanCompleted($this, $nodeFactory, $detect);
+ $visitor->scanCompleted($this, $node);
return;
}
if ($driver->isLeaf($found)) {
if ($leafVerifier->can($driver->getDataForFilter())) {
- $visitor->visitLeaf($this, $nodeFactory, $detect, $found);
+ $visitor->visitLeaf($this, $node, $found);
}
} else {
if ($nodeVerifier->can($driver->getDataForFilter())) {
- $visitor->visitNode($this, $nodeFactory, $detect, $found);
+ $visitor->visitNode($this, $node, $found);
}
}
}
- $visitor->scanCompleted($this, $nodeFactory, $detect);
+ $visitor->scanCompleted($this, $node);
}
}
\ No newline at end of file
diff --git a/src/Verifier.php b/src/Verifier.php
index 10643b0..7716cf1 100644
--- a/src/Verifier.php
+++ b/src/Verifier.php
@@ -5,11 +5,10 @@
class Verifier
{
- /** @var Checker|null */
- private $initialChecker;
- /** @var Checker|null */
- private $checker;
+ private Checker|null $initialChecker;
+
+ private Checker|null $checker;
/**
* @param Filter $filter
@@ -30,7 +29,7 @@ public function append(Filter $filter): Verifier
* @param mixed $verifiable
* @return bool
*/
- public function can($verifiable): bool
+ public function can(mixed $verifiable): bool
{
if (empty($this->initialChecker)) {
return true;
@@ -38,9 +37,13 @@ public function can($verifiable): bool
return $this->initialChecker->can($verifiable);
}
- public function clear()
+ /**
+ * @return void
+ */
+ public function clear(): void
{
$this->initialChecker = null;
$this->checker = null;
}
+
}
\ No newline at end of file
diff --git a/src/Visitor.php b/src/Visitor.php
index 874351c..82e4ad4 100644
--- a/src/Visitor.php
+++ b/src/Visitor.php
@@ -5,40 +5,37 @@
interface Visitor
{
+
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param $detect
+ * @param mixed $detect
+ * @return void
*/
- public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): void;
+ public function scanStarted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void;
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
- * @param $detect
+ * @param mixed $detect
+ * @return void
*/
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void;
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, mixed $detect): void;
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
- * @param $detect
- * @param $found
- * @param null $data
+ * @param mixed $parentNode
+ * @param mixed $currentElement
+ * @param mixed|null $data
+ * @return void
*/
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void;
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentElement, mixed $data = null): void;
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
- * @param $detect
- * @param $found
- * @param null $data
+ * @param mixed $parentNode
+ * @param mixed $currentNode
+ * @param mixed|null $data
+ * @return void
*/
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void;
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, mixed $parentNode, mixed $currentNode, mixed $data = null): void;
- /**
- * @param Visitor $visitor
- * @return bool
- */
- public function equals(Visitor $visitor): bool;
}
\ No newline at end of file
diff --git a/tests/Cases/Dummy/DummyNodeFactory.php b/tests/Cases/Dummy/DummyNodeFactory.php
deleted file mode 100644
index 0f929e5..0000000
--- a/tests/Cases/Dummy/DummyNodeFactory.php
+++ /dev/null
@@ -1,22 +0,0 @@
-testCase->scanCompleted($scanStrategy, $factory, $detect);
+ $this->testCase->scanCompleted($scanStrategy, $detect);
}
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
- * @param $detect
- * @param $found
- * @param null $data
+ * @param $parentNode
+ * @param $currentElement
+ * @param $data
+ * @return void
*/
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $parentNode, $currentElement, $data = null): void
{
- $this->testCase->visitLeaf($scanStrategy, $factory, $detect, $found, $data);
+ $this->testCase->visitLeaf($scanStrategy, $parentNode, $currentElement, $data);
}
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
- * @param $detect
- * @param $found
- * @param null $data
+ * @param $parentNode
+ * @param $currentNode
+ * @param $data
+ * @return void
*/
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $parentNode, $currentNode, $data = null): void
{
- $this->testCase->visitNode($scanStrategy, $factory, $detect, $found, $data);
+ $this->testCase->visitNode($scanStrategy, $parentNode, $currentNode, $data);
}
public function equals(Visitor $visitor): bool
diff --git a/tests/Cases/StrategyCase.php b/tests/Cases/StrategyCase.php
index 245b143..3a73dee 100644
--- a/tests/Cases/StrategyCase.php
+++ b/tests/Cases/StrategyCase.php
@@ -5,7 +5,6 @@
use PHPUnit\Framework\TestCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
-use Vinograd\Scanner\NodeFactory;
abstract class StrategyCase extends TestCase
{
@@ -17,26 +16,26 @@ abstract public function scanStarted(AbstractTraversalStrategy $scanStrategy, $d
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
* @param $detect
+ * @return void
*/
- abstract public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void;
+ abstract public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void;
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
* @param $detect
* @param $found
- * @param null $data
+ * @param $data
+ * @return void
*/
- abstract public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void;
+ abstract public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void;
/**
* @param AbstractTraversalStrategy $scanStrategy
- * @param NodeFactory $factory
* @param $detect
* @param $found
- * @param null $data
+ * @param $data
+ * @return void
*/
- abstract public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void;
+ abstract public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void;
}
\ No newline at end of file
diff --git a/tests/Unit/ArrayDriverTest.php b/tests/Unit/ArrayDriverTest.php
index 9ab83f3..3086cfc 100644
--- a/tests/Unit/ArrayDriverTest.php
+++ b/tests/Unit/ArrayDriverTest.php
@@ -3,7 +3,6 @@
namespace Test\Unit;
-use Test\Cases\Dummy\DummyNodeFactory;
use Vinograd\Scanner\ArrayDriver;
use PHPUnit\Framework\TestCase;
@@ -34,8 +33,8 @@ public function testIsLeafWithSnap()
public function testNormalise()
{
$arrayDriver = new ArrayDriver();
- $result = $arrayDriver->normalise($control = ['value']);
- $result2 = $arrayDriver->normalise($control2 = 'string');
+ $result = $arrayDriver->normalize($control = ['value']);
+ $result2 = $arrayDriver->normalize($control2 = 'string');
self::assertEquals($result, $control);
self::assertEquals($result2, [$control2]);
}
diff --git a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyTest.php b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyTest.php
index a125632..1d4419e 100644
--- a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyTest.php
+++ b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyTest.php
@@ -3,20 +3,17 @@
namespace Test\Unit\BreadthTraversalStrategy;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Verifier;
class BreadthStrategyTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $detect;
private $leafCounter = 0;
@@ -29,7 +26,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -39,7 +35,7 @@ public function setUp(): void
public function testDetect($array, $expectedLeaf, $expectedNodes)
{
$verifier = new Verifier();
- $this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
+ $this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier, $this->provider);
self::assertEquals($this->leafCounter, count($expectedLeaf));
self::assertEquals($this->nodeCounter, count($expectedNodes));
@@ -107,18 +103,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
@@ -129,7 +125,6 @@ public function tearDown(): void
{
$this->strategy = null;
$this->driver = null;
- $this->factory = null;
$this->detect = null;
$this->leafCounter = 0;
diff --git a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithBeforeStopTest.php b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithBeforeStopTest.php
index 19d5a6d..d0d1ca1 100644
--- a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithBeforeStopTest.php
+++ b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithBeforeStopTest.php
@@ -3,13 +3,11 @@
namespace Test\Unit\BreadthTraversalStrategy;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Verifier;
class BreadthStrategyWithBeforeStopTest extends StrategyCase
@@ -43,7 +41,7 @@ public function testDetect()
],
4
],
- ], $driver, new DummyNodeFactory(), $verifier, $verifier, $provider);
+ ], $driver, $verifier, $verifier, $provider);
self::assertTrue(true);
}
@@ -54,17 +52,17 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::fail();
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::fail();
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::fail();
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::fail();
}
diff --git a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithStopTest.php b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithStopTest.php
index 0fa4720..41a935c 100644
--- a/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithStopTest.php
+++ b/tests/Unit/BreadthTraversalStrategy/BreadthStrategyWithStopTest.php
@@ -3,20 +3,17 @@
namespace Test\Unit\BreadthTraversalStrategy;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Verifier;
class BreadthStrategyWithStopTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $detect;
private $provider;
@@ -24,7 +21,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -34,7 +30,7 @@ public function setUp(): void
public function testDetect($array)
{
$verifier = new Verifier();
- $this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
+ $this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier, $this->provider);
}
public function getCase()
@@ -71,12 +67,12 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::assertTrue(true);
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::assertTrue(true);
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertCount(1, $found);
$key = array_keys($found)[0];
@@ -87,7 +83,7 @@ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $
}
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertTrue(true);
}
diff --git a/tests/Unit/Scanner/ScannerSnapTest.php b/tests/Unit/Scanner/ScannerSnapTest.php
index 0278bfb..1a340c3 100644
--- a/tests/Unit/Scanner/ScannerSnapTest.php
+++ b/tests/Unit/Scanner/ScannerSnapTest.php
@@ -3,13 +3,11 @@
namespace Test\Unit\Scanner;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\DummyVisitor;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\Driver;
use Vinograd\Scanner\Exception\ConfigurationException;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
use PHPUnit\Framework\TestCase;
use Vinograd\Scanner\SingleStrategy;
@@ -53,11 +51,6 @@ public function testConstruct()
$objectValue = $property->getValue($scanner);
self::assertEmpty($objectValue);
- $reflection = new \ReflectionObject($scanner);
- $property = $reflection->getProperty('nodeFactory');
- $property->setAccessible(true);
- $objectValue = $property->getValue($scanner);
- self::assertEmpty($objectValue);
}
public function testSetStrategy()
@@ -91,20 +84,13 @@ public function testSetDriver()
self::assertSame($driver, $scanner->getDriver());
}
- public function testGetNodeFactory()
- {
- $scanner = new Scanner();
- $scanner->setNodeFactory($nodeFactory = $this->getMockForAbstractClass(NodeFactory::class));
- self::assertSame($nodeFactory, $scanner->getNodeFactory());
- }
-
public function testSearchNoDriver()
{
$this->expectException(ConfigurationException::class);
$scanner = new Scanner();
$scanner->setStrategy(new SingleStrategy());
$scanner->setVisitor(new DummyVisitor());
- $scanner->search([]);
+ $scanner->traverse([]);
}
public function testSearchNoStrategy()
@@ -113,7 +99,7 @@ public function testSearchNoStrategy()
$scanner = new Scanner();
$scanner->setDriver($this->getMockForAbstractClass(Driver::class));
$scanner->setVisitor(new DummyVisitor());
- $scanner->search([]);
+ $scanner->traverse([]);
}
public function testSearchNoVisitor()
@@ -122,16 +108,7 @@ public function testSearchNoVisitor()
$scanner = new Scanner();
$scanner->setDriver($this->getMockForAbstractClass(Driver::class));
$scanner->setStrategy(new SingleStrategy());
- $scanner->search([]);
+ $scanner->traverse([]);
}
- public function testSearchNoNodeFactory()
- {
- $this->expectException(ConfigurationException::class);
- $scanner = new Scanner();
- $scanner->setDriver($this->getMockForAbstractClass(Driver::class));
- $scanner->setStrategy(new SingleStrategy());
- $scanner->setVisitor(new DummyVisitor());
- $scanner->search([]);
- }
}
diff --git a/tests/Unit/Scanner/SearchTest.php b/tests/Unit/Scanner/SearchTest.php
index 3a89fc1..edb3c6a 100644
--- a/tests/Unit/Scanner/SearchTest.php
+++ b/tests/Unit/Scanner/SearchTest.php
@@ -3,20 +3,17 @@
namespace Test\Unit\Scanner;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
class SearchTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $leafCounter = 0;
private $nodeCounter = 0;
@@ -28,7 +25,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -41,8 +37,7 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
- $scanner->setNodeFactory($this->factory);
- $scanner->search($array);
+ $scanner->traverse($array);
self::assertCount($this->leafCounter, $expectedLeaf);
self::assertCount($this->nodeCounter, $expectedNodes);
@@ -111,18 +106,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
diff --git a/tests/Unit/Scanner/SearchWithLeafFilterTest.php b/tests/Unit/Scanner/SearchWithLeafFilterTest.php
index 3547763..3e02798 100644
--- a/tests/Unit/Scanner/SearchWithLeafFilterTest.php
+++ b/tests/Unit/Scanner/SearchWithLeafFilterTest.php
@@ -3,21 +3,18 @@
namespace Test\Unit\Scanner;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
use Vinograd\Scanner\Filter;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
class SearchWithLeafFilterTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $leafCounter = 0;
private $nodeCounter = 0;
@@ -29,7 +26,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -42,13 +38,12 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
- $scanner->setNodeFactory($this->factory);
$scanner->addLeafFilter(new class() implements Filter {
- public function filter($found): bool
+ public function filter($element): bool
{
- $value = array_values($found)[0];
+ $value = array_values($element)[0];
if ('zero' === $value) {
return false;
}
@@ -64,7 +59,7 @@ public function setConfiguration($config): void
}
});
- $scanner->search($array);
+ $scanner->traverse($array);
self::assertCount($this->leafCounter, $expectedLeaf);
self::assertCount($this->nodeCounter, $expectedNodes);
@@ -131,18 +126,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
diff --git a/tests/Unit/Scanner/SearchWithNodeFilterTest.php b/tests/Unit/Scanner/SearchWithNodeFilterTest.php
index 4599b84..ea7cb63 100644
--- a/tests/Unit/Scanner/SearchWithNodeFilterTest.php
+++ b/tests/Unit/Scanner/SearchWithNodeFilterTest.php
@@ -10,7 +10,6 @@
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
use Vinograd\Scanner\Filter;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
class SearchWithNodeFilterTest extends StrategyCase
@@ -34,13 +33,12 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($strategy);
$scanner->setVisitor($provider);
$scanner->setDriver($driver);
- $scanner->setNodeFactory(new DummyNodeFactory());
$scanner->addNodeFilter(new class() implements Filter {
- public function filter($found): bool
+ public function filter($element): bool
{
- $key = array_keys($found)[0];
+ $key = array_keys($element)[0];
if ($key === 'key3') {
return false;
}
@@ -53,7 +51,7 @@ public function setConfiguration($config): void
}
});
- $scanner->search($array);
+ $scanner->traverse($array);
self::assertCount($this->leafCounter, $expectedLeaf);
self::assertCount($this->nodeCounter, $expectedNodes);
@@ -122,18 +120,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
$this->nodeLog[] = $found;
diff --git a/tests/Unit/Scanner/SearchWithResetLeafFilterTest.php b/tests/Unit/Scanner/SearchWithResetLeafFilterTest.php
index ee6d49b..d5fbf06 100644
--- a/tests/Unit/Scanner/SearchWithResetLeafFilterTest.php
+++ b/tests/Unit/Scanner/SearchWithResetLeafFilterTest.php
@@ -10,14 +10,12 @@
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
use Vinograd\Scanner\Filter;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
class SearchWithResetLeafFilterTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $leafCounter = 0;
private $nodeCounter = 0;
@@ -29,7 +27,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -42,13 +39,12 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
- $scanner->setNodeFactory($this->factory);
$scanner->addLeafFilter(new class() implements Filter {
- public function filter($found): bool
+ public function filter($element): bool
{
- $value = array_values($found)[0];
+ $value = array_values($element)[0];
if ('zero' === $value) {
return false;
}
@@ -64,7 +60,7 @@ public function setConfiguration($config): void
}
});
$scanner->resetLeafFilters();
- $scanner->search($array);
+ $scanner->traverse($array);
self::assertCount($this->leafCounter, $expectedLeaf);
self::assertCount($this->nodeCounter, $expectedNodes);
@@ -133,18 +129,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
@@ -155,7 +151,6 @@ public function tearDown(): void
{
$this->strategy = null;
$this->driver = null;
- $this->factory = null;
$this->leafCounter = 0;
$this->nodeCounter = 0;
diff --git a/tests/Unit/Scanner/SearchWithResetNodeFilterTest.php b/tests/Unit/Scanner/SearchWithResetNodeFilterTest.php
index 893caf9..a56854c 100644
--- a/tests/Unit/Scanner/SearchWithResetNodeFilterTest.php
+++ b/tests/Unit/Scanner/SearchWithResetNodeFilterTest.php
@@ -3,14 +3,12 @@
namespace Test\Unit\Scanner;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\BreadthStrategy;
use Vinograd\Scanner\Filter;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
class SearchWithResetNodeFilterTest extends StrategyCase
@@ -34,13 +32,12 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($strategy);
$scanner->setVisitor($provider);
$scanner->setDriver($driver);
- $scanner->setNodeFactory(new DummyNodeFactory());
$scanner->addNodeFilter(new class() implements Filter {
- public function filter($found): bool
+ public function filter($element): bool
{
- $key = array_keys($found)[0];
+ $key = array_keys($element)[0];
if ($key === 'key3') {
return false;
}
@@ -53,7 +50,7 @@ public function setConfiguration($config): void
}
});
$scanner->resetNodeFilters();
- $scanner->search($array);
+ $scanner->traverse($array);
self::assertCount($this->leafCounter, $expectedLeaf);
self::assertCount($this->nodeCounter, $expectedNodes);
@@ -126,18 +123,18 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->leafCounter++;
$this->leafLog [] = $found;
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
$this->nodeCounter++;
$this->nodeLog[] = $found;
diff --git a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectSnapTest.php b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectSnapTest.php
index a65bbb5..8760766 100644
--- a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectSnapTest.php
+++ b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectSnapTest.php
@@ -3,12 +3,10 @@
namespace Test\Unit\SingleTraversalStrategy;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\SingleStrategy;
use Vinograd\Scanner\Verifier;
@@ -16,7 +14,6 @@ class SingleStrategyDetectSnapTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $detect;
private $verifier1;
private $verifier2;
@@ -26,7 +23,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new SingleStrategy();
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
$this->verifier1 = new Verifier();
$this->verifier2 = new Verifier();
@@ -38,7 +34,7 @@ public function setUp(): void
public function testDetect($array)
{
$this->detect = $array;
- $this->strategy->detect($array, $this->driver, $this->factory, $this->verifier1, $this->verifier2, $this->provider);
+ $this->strategy->detect($array, $this->driver, $this->verifier1, $this->verifier2, $this->provider);
}
public function getCase()
@@ -75,34 +71,30 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::assertEquals($this->strategy, $scanStrategy);
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::assertEquals($this->detect, $detect);
self::assertEquals($this->strategy, $scanStrategy);
- self::assertEquals($this->factory, $factory);
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertEmpty($data);
self::assertEquals($this->detect, $detect);
self::assertEquals($this->strategy, $scanStrategy);
- self::assertEquals($this->factory, $factory);
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertEmpty($data);
self::assertEquals($this->detect, $detect);
self::assertEquals($this->strategy, $scanStrategy);
- self::assertEquals($this->factory, $factory);
}
public function tearDown(): void
{
$this->strategy = null;
$this->driver = null;
- $this->factory = null;
$this->detect = null;
$this->verifier1 = null;
$this->verifier2 = null;
diff --git a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectTest.php b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectTest.php
index f453ba3..5408f18 100644
--- a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectTest.php
+++ b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectTest.php
@@ -3,12 +3,10 @@
namespace Test\Unit\SingleTraversalStrategy;
-use Test\Cases\Dummy\DummyNodeFactory;
use Test\Cases\Dummy\TestCaseProviderVisitor;
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\SingleStrategy;
use Vinograd\Scanner\Verifier;
@@ -16,7 +14,6 @@ class SingleStrategyDetectTest extends StrategyCase
{
private $strategy;
private $driver;
- private $factory;
private $detect;
private $array;
private $except;
@@ -26,7 +23,6 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new SingleStrategy();
- $this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver();
}
@@ -38,7 +34,7 @@ public function testDetect($array, $except)
$this->array = $array;
$this->except = $except;
$verifier = new Verifier();
- $this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
+ $this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier, $this->provider);
}
public function getCase()
@@ -131,13 +127,13 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::assertEquals($this->strategy, $scanStrategy);
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::assertEmpty($this->except['node']);
self::assertEmpty($this->except['leaf']);
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertCount(1, $found);
$key = array_keys($found)[0];
@@ -150,7 +146,7 @@ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $
}
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertCount(1, $found);
$key = array_keys($found)[0];
diff --git a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithBeforeStopTest.php b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithBeforeStopTest.php
index 8f22751..5cac804 100644
--- a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithBeforeStopTest.php
+++ b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithBeforeStopTest.php
@@ -8,7 +8,6 @@
use Test\Cases\StrategyCase;
use Vinograd\Scanner\AbstractTraversalStrategy;
use Vinograd\Scanner\ArrayDriver;
-use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\SingleStrategy;
use Vinograd\Scanner\Verifier;
@@ -30,7 +29,7 @@ public function testDetect()
'key2' => 'value2',
'key3' => [4.5, 4],
'key4' => [1, 3, 2]
- ], $driver,new DummyNodeFactory(), $verifier, $verifier, $provider);
+ ], $driver, $verifier, $verifier, $provider);
self::assertTrue(true);
}
@@ -40,17 +39,17 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::fail();
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::fail();
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::fail();
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::fail();
}
diff --git a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithStopTest.php b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithStopTest.php
index 42f1eb2..fcf1bdd 100644
--- a/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithStopTest.php
+++ b/tests/Unit/SingleTraversalStrategy/SingleStrategyDetectWithStopTest.php
@@ -33,7 +33,7 @@ public function testDetect($array, $found)
{
$this->found = $found;
$verifier = new Verifier();
- $this->strategy->detect( $array, $this->driver,new DummyNodeFactory(), $verifier, $verifier,$this->provider);
+ $this->strategy->detect( $array, $this->driver,$verifier, $verifier,$this->provider);
}
public function getCase()
@@ -72,12 +72,12 @@ public function scanStarted(AbstractTraversalStrategy $scanStrategy, $detect): v
self::assertTrue(true);
}
- public function scanCompleted(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect): void
+ public function scanCompleted(AbstractTraversalStrategy $scanStrategy, $detect): void
{
self::assertTrue(true);
}
- public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertCount(1, $found);
$key = array_keys($found)[0];
@@ -88,7 +88,7 @@ public function visitLeaf(AbstractTraversalStrategy $scanStrategy, NodeFactory $
}
}
- public function visitNode(AbstractTraversalStrategy $scanStrategy, NodeFactory $factory, $detect, $found, $data = null): void
+ public function visitNode(AbstractTraversalStrategy $scanStrategy, $detect, $found, $data = null): void
{
self::assertCount(1, $found);
$key = array_keys($found)[0];
diff --git a/tests/Unit/VerifierTest.php b/tests/Unit/VerifierTest.php
index f2f8fce..09710d5 100644
--- a/tests/Unit/VerifierTest.php
+++ b/tests/Unit/VerifierTest.php
@@ -4,7 +4,6 @@
namespace Test\Unit;
use Vinograd\Scanner\Filter;
-use Vinograd\Scanner\Leaf;
use Vinograd\Scanner\Verifier;
use PHPUnit\Framework\TestCase;
@@ -45,18 +44,26 @@ public function setConfiguration($config): void
}
});
- $coolFile = $this->createStub(Leaf::class);
- $coolFile->method('getSource')
- ->willReturn('conftest1.php');
-
+ $coolFile = new class() {
+ public function getSource()
+ {
+ return 'conftest1.php';
+ }
+ };
- $badFile = $this->createStub(Leaf::class);
- $badFile->method('getSource')
- ->willReturn('conftest1.yml');
+ $badFile = new class() {
+ public function getSource()
+ {
+ return 'conftest1.yml';
+ }
+ };
- $badFile2 = $this->createStub(Leaf::class);
- $badFile2->method('getSource')
- ->willReturn('contest1.yml');
+ $badFile2 = new class() {
+ public function getSource()
+ {
+ return 'contest1.yml';
+ }
+ };
self::assertTrue($verifier->can($coolFile));
self::assertFalse($verifier->can($badFile));
@@ -85,13 +92,19 @@ public function setConfiguration($config): void
}
});
- $coolFile2 = $this->createStub(Leaf::class);
- $coolFile2->method('getSource')
- ->willReturn('conf.php');
+ $coolFile2 = new class() {
+ public function getSource()
+ {
+ return 'conf.php';
+ }
+ };
- $badFile3 = $this->createStub(Leaf::class);
- $badFile3->method('getSource')
- ->willReturn('conf.dhp');
+ $badFile3 = new class() {
+ public function getSource()
+ {
+ return 'conf.dhp';
+ }
+ };
self::assertTrue($verifier2->can($coolFile2));
self::assertFalse($verifier2->can($badFile3));
@@ -104,9 +117,9 @@ public function setConfiguration($config): void
public function testAppendCountFilters()
{
$verifier = new Verifier();
- $verifier->append($filter1=$this->getMockForAbstractClass(Filter::class))
- ->append($filter2=$this->getMockForAbstractClass(Filter::class))
- ->append($filter3=$this->getMockForAbstractClass(Filter::class));
+ $verifier->append($filter1 = $this->getMockForAbstractClass(Filter::class))
+ ->append($filter2 = $this->getMockForAbstractClass(Filter::class))
+ ->append($filter3 = $this->getMockForAbstractClass(Filter::class));
$leafVerifierObjectValueReflection = new \ReflectionObject($verifier);
$initialCheckerProperty = $leafVerifierObjectValueReflection->getProperty('initialChecker');