Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OnHold|Feat] Add PhpStan #211

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3435463
Feat: Added support for formatting the result to json.
olivernybroe Jun 25, 2019
a0791a0
Fix: Fix styling and bug when using verbose output
olivernybroe Jun 25, 2019
e2ad017
Fix: Fix newline issue
olivernybroe Jun 25, 2019
25a0c4e
Fix: Fix PHPStan error
olivernybroe Jun 25, 2019
1733f0c
Fix: Fix so ANSI support correctly...
olivernybroe Jun 25, 2019
16e26cd
Fix: Fixed a bunch of styling and loop in json formatter
olivernybroe Jun 26, 2019
fd9059c
Feat: Add details class
olivernybroe Jun 26, 2019
b23c9e2
Feat: Added message about using fallback format, if invalid format.
olivernybroe Jun 26, 2019
604de75
Style: Fix unused comments and added some
olivernybroe Jun 27, 2019
9869dbf
Docs: Add docs about formatters and piping
olivernybroe Jul 4, 2019
a831fbd
Docs: Add json schema file for json format.
olivernybroe Jul 4, 2019
50a8291
Docs: Add json schema file for json format.
olivernybroe Jul 4, 2019
3190a70
Feat: phpstan support
olivernybroe Jul 5, 2019
a0f570c
Merge branch 'feat-formatter' of github.com:olivernybroe/phpinsights …
olivernybroe Jul 5, 2019
c0f3a6e
Feat: Add correct reporting of phpstan
olivernybroe Jul 5, 2019
a4fbd53
Feat: start refactoring for runner class
olivernybroe Jul 8, 2019
2c0a1af
Style: Made some style changes
olivernybroe Jul 8, 2019
261dedd
style: Fix phpstan error
olivernybroe Jul 8, 2019
cb13660
Style: Add some type hints and style fixes
olivernybroe Jul 8, 2019
e7ae36a
Style: Add some type hints and style fixes
olivernybroe Jul 8, 2019
dc779c2
Style: Exclude reflection for forbidden setter sniff
olivernybroe Jul 8, 2019
b3061ad
Refactor: Changed with to setters in details class
olivernybroe Jul 9, 2019
03f55ea
Refactor: Added a new class called runner to use in the insight factory
olivernybroe Jul 9, 2019
9acc31a
WIP
olivernybroe Jul 17, 2019
9230d2a
Merge branch 'feat-formatter' of github.com:olivernybroe/phpinsights …
olivernybroe Jul 17, 2019
0a481b1
Feat: Add php stan file processor
olivernybroe Jul 18, 2019
111e4eb
Refactor: Remove the need for phpstan analyser class
olivernybroe Jul 18, 2019
88d0b0c
Refactor: A gigantic refactoring
olivernybroe Jul 19, 2019
56bea8f
Refactor: Removed the dependency for symplify
olivernybroe Jul 19, 2019
8b60c98
Fix: Fixed some autoloading issues in phpstan file processor
olivernybroe Jul 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[*.php]
ij_php_align_phpdoc_comments = false
ij_php_align_phpdoc_param_names = false
ij_php_phpdoc_use_fqcn = true
ij_php_space_after_unary_not = true
ij_php_force_short_declaration_array_style = true
ij_php_comma_after_last_array_element = true
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
"ext-json": "*",
"composer/composer": "^1.7",
"league/container": "^3.2",
"nunomaduro/larastan": "^0.3.17",
"object-calisthenics/phpcs-calisthenics-rules": "^3.5",
"phploc/phploc": "^5.0",
"phpstan/phpstan": "^0.11.12",
"phpstan/phpstan-strict-rules": "^0.11.1",
"sensiolabs/security-checker": "^6.0",
"squizlabs/php_codesniffer": "^3.4",
"symfony/console": "^4.2",
"symfony/finder": "^4.2",
"symplify/coding-standard": "^6.0",
"symplify/easy-coding-standard": "^6.0",
"symplify/package-builder": "^6.0"
"symfony/finder": "^4.2"
},
"require-dev": {
"illuminate/console": "^5.8",
"illuminate/database": "^5.8",
"illuminate/support": "^5.8",
"localheinz/phpstan-rules": "^0.10.0",
"phpstan/phpstan-strict-rules": "^0.11",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0",
"roave/no-floaters": "^1.1",
"phpstan/phpstan": "^0.11.5",
"symfony/var-dumper": "^4.2",
"thecodingmachine/phpstan-strict-rules": "^0.11.0",
"phpunit/phpunit": "^8.0",
"mockery/mockery": "^1.0"
"symplify/easy-coding-standard": "^6.0",
"thecodingmachine/phpstan-strict-rules": "^0.11.0"
},
"autoload-dev": {
"psr-4": {
Expand Down Expand Up @@ -65,7 +66,7 @@
"ecs:test": "ecs check src --ansi --config vendor/symplify/easy-coding-standard/config/set/clean-code.yaml",
"phpstan:test": "phpstan analyse --ansi",
"phpunit:test": "phpunit --colors=always",
"insights": "bin/phpinsights analyse --ansi -v --no-interaction --min-quality=85.7 --min-architecture=76.2 --min-style=97.8",
"insights": "bin/phpinsights analyse --ansi -v --no-interaction --min-quality=90.0 --min-architecture=80.0 --min-style=97.8",
"test": [
"@phpstan:test",
"@ecs:test",
Expand Down
12 changes: 8 additions & 4 deletions docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

The project is under development. As such, any help is welcome!

1. [Create a new insight from scratch](#create-a-new-insight)
2. [Add a new insight from PHP CS Sniff](#add-a-new-insight-from-php-cs-sniff)
3. [Create or improve create a preset for your favorite framework](#create-or-improve-create-a-preset-for-your-favorite-framework)
4. [Create the test suite](#create-the-test-suite)
[[TOC]]

## Create a new `Insight`

Expand Down Expand Up @@ -129,3 +126,10 @@ final class Preset implements PresetContract
}
}
```

## Create a new `Formatter`

The package has support for formatting the result.
All formats implements the contract `src/Application/Console/Contracts/Formatter`.

You are welcome to contribute with new formats or improve on the ones we already have.
25 changes: 25 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ In laravel, launch command as usual with your path:
php artisan insights path/to/analyse
```

## Formatting the output

For changing the output format you can add the `format` flag. The following formats are supported:

- console
- json

```bash
./vendor/bin/phpinsights analyse --format=json
```

## Saving output to file

You can pipe the result to a file or to anywhere you like.
A common use case is parsing the output formatted as json to a json file.

```bash
./vendor/bin/phpinsights analyse --format=json > test.json
```

When piping the result remember to add the no interaction flag `-n`, as the part where you need to interact is also getting piped. (the json format does not have any interaction)
While piping data, if you want the progress bar to refresh itself instead of printing a new one, add the `--ansi` flag.



## Allowed memory size of X bytes exhausted

If you encounter the error `Allowed memory size of XXXXX bytes exhausted`, the current workaround is to increase the memory limit:
Expand Down
22 changes: 22 additions & 0 deletions phpinsights.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

declare(strict_types=1);

use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalConstants;
use NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff;

return [

Expand Down Expand Up @@ -46,6 +49,25 @@
LineLengthSniff::class => [
'lineLimit' => 80,
'absoluteLineLimit' => 120,
'ignoreComments' => true,
],
DisallowMixedTypeHintSniff::class => [
'exclude' => [
'src/Domain/Reflection.php',
'src/Domain/Details.php',
],
],
ForbiddenSetterSniff::class => [
'exclude' => [
'src/Domain/Reflection.php',
'src/Domain/Details.php',
],
],
ForbiddenDefineGlobalConstants::class => [
'ignore' => [
'PHP_CODESNIFFER_VERBOSITY',
'PHP_CODESNIFFER_CBF',
],
],
],

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ parameters:
- '#Language construct isset\(\) should not be used#'
- '#Access to an undefined property PHP_CodeSniffer\\Config::\$standards.#'
- '#Access to an undefined property PHP_CodeSniffer\\Sniffs\\Sniff::\$#'
- '#NunoMaduro\\PhpInsights\\Application\\Console\\Formatters\\Json has an unused parameter \$input#'
autoload_files:
- %rootDir%/../../squizlabs/php_codesniffer/autoload.php
reportUnmatchedIgnoredErrors: false
Expand Down
101 changes: 101 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"readOnly": true,
"title": "The JSON format for phpinsights",
"required": [
"summary",
"Code",
"Complexity",
"Architecture",
"Style",
"Security"
],
"definitions": {
"percentage": {
"type": "number",
"minimum": 0,
"maximum": 100
},
"insight": {
"type": "object",
"required": [
"title",
"insightClass"
],
"properties": {
"title": {
"type": "string"
},
"insightClass": {
"type": "string"
},
"file": {
"type": "string"
},
"line": {
"type": "integer",
"minimum": 1
},
"message": {
"type": "string"
}
}
}
},
"properties": {
"summary": {
"$id": "#/properties/summary",
"type": "object",
"title": "The Summary Schema",
"properties": {
"code": {
"$ref": "#/definitions/percentage"
},
"complexity": {
"$ref": "#/definitions/percentage"
},
"architecture": {
"$ref": "#/definitions/percentage"
},
"style": {
"$ref": "#/definitions/percentage"
},
"security issues": {
"type": "integer",
"minimum": 0
}
}
},
"Code": {
"type": "array",
"items": {
"$ref": "#/definitions/insight"
}
},
"Complexity": {
"type": "array",
"items": {
"$ref": "#/definitions/insight"
}
},
"Architecture": {
"type": "array",
"items": {
"$ref": "#/definitions/insight"
}
},
"Style": {
"type": "array",
"items": {
"$ref": "#/definitions/insight"
}
},
"Security": {
"type": "array",
"items": {
"$ref": "#/definitions/insight"
}
}
}
}
33 changes: 17 additions & 16 deletions src/Application/Console/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace NunoMaduro\PhpInsights\Application\Console;

use NunoMaduro\PhpInsights\Application\Console\Contracts\Formatter;
use NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory;
use NunoMaduro\PhpInsights\Domain\MetricsFinder;
use NunoMaduro\PhpInsights\Domain\Results;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
Expand All @@ -21,7 +23,7 @@ final class Analyser
/**
* Analyser constructor.
*
* @param \NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory $insightCollectionFactory
* @param \NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory $insightCollectionFactory
*/
public function __construct(InsightCollectionFactory $insightCollectionFactory)
{
Expand All @@ -31,28 +33,27 @@ public function __construct(InsightCollectionFactory $insightCollectionFactory)
/**
* Analyse the given dirs.
*
* @param \NunoMaduro\PhpInsights\Application\Console\Style $style
* @param array<string, array> $config
* @param string $dir
* @param Formatter $formatter
* @param array<string, array> $config
* @param string $dir
* @param OutputInterface $consoleOutput
*
* @return \NunoMaduro\PhpInsights\Domain\Results
*/
public function analyse(Style $style, array $config, string $dir): Results
public function analyse(
Formatter $formatter,
array $config,
string $dir,
OutputInterface $consoleOutput
): Results
{
$metrics = MetricsFinder::find();

$insightCollection = $this->insightCollectionFactory->get($metrics, $config, $dir);
$insightCollection = $this->insightCollectionFactory
->get($metrics, $config, $dir, $consoleOutput);

$results = $insightCollection->results();
$formatter->format($insightCollection, $dir, $metrics);

$style->header($results, $dir)
->code($insightCollection, $results)
->complexity($insightCollection, $results)
->architecture($insightCollection, $results)
->misc($results);

$style->issues($insightCollection, $metrics, $dir);

return $results;
return $insightCollection->results();
}
}
Loading