The project is under development. As such, any help is welcome!
[[TOC]]
Imagine that you want to create a new Insight
that doesn't allow the usage of final classes:
- Create a new file under
src/Domain/Insights
with the content:
final class ForbiddenFinalClasses extends Insight
{
public function hasIssue(): bool
{
return (bool) count($this->collector->getConcreteFinalClasses());
}
public function getTitle(): string
{
return 'The use of `final` classes is prohibited';
}
}
- Attach the
Insight
to a specific Metric insidesrc/Domain/Metrics
:
final class Classes implements HasInsights
{
// ...
public function getInsights(): array
{
return [
ForbiddenFinalClasses::class,
];
}
}
Are you aware of a PHPCS sniff that you would like to add to PHP Insights? You can add it in the following way:
- Identify the related metric, and add it to the list of insights:
final class Classes implements HasInsights
{
// ...
public function getInsights(): array
{
return [
UnusedPropertySniff::class,
];
}
}
Would you like to exclude a directory or remove an Insight
for your favorite framework? You can add it in the following way:
In this example we are going to use the Laravel Framework.
- Open the file
src/Application/Adapters/Laravel/Preset.php
and update the config file:
final class Preset implements PresetContract
{
public static function getName(): string
{
return 'laravel';
}
public static function get(): array
{
return [
'exclude' => [
'config',
'storage',
'resources',
'bootstrap',
'nova',
'database',
'server.php',
'_ide_helper.php',
'_ide_helper_models.php',
'public',
],
'add' => [
Classes::class => [
ForbiddenFinalClasses::class,
],
],
'remove' => [
AlphabeticallySortedUsesSniff::class,
DeclareStrictTypesSniff::class,
DisallowMixedTypeHintSniff::class,
ForbiddenDefineFunctions::class,
ForbiddenNormalClasses::class,
ForbiddenTraits::class,
TypeHintDeclarationSniff::class,
],
'config' => [
ForbiddenPrivateMethods::class => [
'title' => 'The usage of private methods is not idiomatic in Laravel.',
],
ForbiddenDefineGlobalConstants::class => [
'ignore' => ['LARAVEL_START'],
],
ForbiddenFunctionsSniff::class => [
'forbiddenFunctions' => [
'dd' => null,
'dump' => null,
],
],
],
];
}
}
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.