App uses a number of open source projects to work properly:
- PHP required 7.4 version or later
- Symfony - Symfony, High Performance PHP Framework for Web Development
- Composer - A Dependency Manager for PHP
- PHP_CodeSniffer PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards
- PHPUnit The PHP Testing Framework
- PHPStan PHP Static Analysis Tool - discover bugs in your code without running it!
The application uses the following coding standards and quality tools:
The Doctrine Coding Standard is a set of rules for PHP_CodeSniffer. It is based on PSR-1 and PSR-2 , with some noticeable exceptions/differences/extensions.
- Keep the nesting of control structures per method as small as possible
- Abstract exception class names and exception interface names should be suffixed with
Exception
- Abstract classes should not be prefixed or suffixed with
Abstract
- Interfaces should not be prefixed or suffixed with
Interface
- Concrete exception class names should not be prefixed or suffixed with
Exception
- Align equals (
=
) signs in assignments - Add spaces around a concatenation operator
$foo = 'Hello ' . 'World!';
- Add spaces between assignment, control and return statements
- Add spaces after a negation operator
if (! $cond)
- Add spaces around a colon in return type declaration
function () : void {}
- Add spaces after a type cast
$foo = (int) '12345';
- Use apostrophes for enclosing strings
- Always use strict comparisons
- Always add
declare(strict_types=1)
at the beginning of a file - Always add native types where possible
- Omit phpDoc for parameters/returns with native types, unless adding description
- Don't use
@author
,@since
and similar annotations that duplicate Git information - Assignment in condition is not allowed
- Use parentheses when creating new instances that do not require arguments
$foo = new Foo()
- Use Null Coalesce Operator
$foo = $bar ?? $baz
- Prefer early exit over nesting conditions or using else
The PSR-2 the most common coding standard among php programmers.
PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.
Tests in directory tests
App requires Composer to install dependencies.
For more information about installing Composer please follow the documentation: https://getcomposer.org/download/
To install php packages you need to execute
$ composer install
To show help in a main app
./task1 --help
or to display updated json you can run
./task1 ./tree.json ./list.json
if you want save output you can do this by using pipe
./task1 ./tree.json ./list.json > new-tree.json
To run all tests (phpcbf, phpcs, phpstan, phpunit) you can run
$ composer tests
Or for running only phpunit tests you can run
$ composer phpunit
> ./vendor/bin/phpunit
PHPUnit 9.1.3 by Sebastian Bergmann and contributors.
................ 16 / 16 (100%)
Time: 00:00.047, Memory: 6.00 MB
OK (16 tests, 40 assertions)
PROPRIETARY
Have fun!