You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
e.g. Symfony\Contracts\Service\Attribute\Required in app/Controller/ProductController.php:24
42
41
43
-
```
42
+
Found unused dependencies!
43
+
(those are listed in composer.json, but no usage was found in scanned paths)
44
+
45
+
• nette/utils
44
46
45
-
You can add `--verbose` flag to see first usage (file & line) of each class.
47
+
```
46
48
47
49
## Detected issues:
48
50
This tool reads your `composer.json` and scans all paths listed in both `autoload` sections while analysing:
@@ -51,20 +53,76 @@ This tool reads your `composer.json` and scans all paths listed in both `autoloa
51
53
- Those are dependencies of your dependencies, which are not listed in `composer.json`
52
54
- Your code can break when your direct dependency gets updated to newer version which does not require that shadowed dependency anymore
53
55
- You should list all those classes within your dependencies
56
+
54
57
-**Unused dependencies**
55
58
- Any non-dev dependency is expected to have at least single usage within the scanned paths
59
+
- To avoid false positives here, you might need to adjust scanned paths or ignore some packages by `--config`
60
+
56
61
-**Dev dependencies in production code**
57
-
- Your code can break once you run your application with `composer install --no-dev`
58
-
- You should move those to `require` from `require-dev`
62
+
- For libraries, this is risky as your users might not have those installed
63
+
- For applications, it can break once you run it with `composer install --no-dev`
64
+
- You should move those from `require-dev` to `require`
65
+
- If you want to ignore some packages here, use `--config`
66
+
59
67
-**Unknown classes**
60
68
- Any class missing in composer classmap gets reported as we cannot say if that one is shadowed or not
61
-
- This might be expected in some cases, so you can disable this behaviour by `--ignore-unknown-classes`
69
+
- This might be expected in some cases, so you can disable this behaviour by `--ignore-unknown-classes` or more granularly by `--config`
62
70
63
71
It is expected to run this tool in root of your project, where the `composer.json` is located.
64
72
If you want to run it elsewhere, you can use `--composer-json=path/to/composer.json` option.
65
73
66
74
Currently, it only supports those autoload sections: `psr-4`, `psr-0`, `files`.
67
75
76
+
## Configuration:
77
+
You can provide custom path to config file by `--config=path/to/config.php` where the config file is PHP file returning `ShipMonk\Composer\Config\Configuration` object.
78
+
Here is example of what you can do:
79
+
80
+
```php
81
+
<?php
82
+
83
+
use ShipMonk\Composer\Config\Configuration;
84
+
use ShipMonk\Composer\Config\ErrorType;
85
+
86
+
$config = new Configuration();
87
+
88
+
return $config
89
+
// disable scanning autoload & autoload-dev paths from composer.json
90
+
// with such option, you should add custom paths by addPathToScan() or addPathsToScan()
91
+
->disableComposerAutoloadPathScan()
92
+
93
+
// disable detection of dev dependencies in production code globally
// allow using classes not present in composer's autoloader
115
+
// e.g. a library may conditionally support some feature only when Memcached is available
116
+
->ignoreUnknownClasses(['Memcached'])
117
+
118
+
// allow using classes not present in composer's autoloader by regex
119
+
// e.g. when you want to ignore whole namespace of classes
120
+
->ignoreUnknownClassesRegex('~^PHPStan\\.*?~')
121
+
;
122
+
```
123
+
124
+
All paths are expected to exist. If you need some glob functionality, you can do it in your config file and pass the expanded list to e.g. `ignoreErrorsOnPaths`.
125
+
68
126
## Limitations:
69
127
- Files without namespace has limited support
70
128
- Only classes with use statements and FQNs are detected
0 commit comments