lynxsolutions/php-static-analysis

Static Analysis Tools Configurations for Laravel projects

Installs: 53

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 4

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

1.0.0 2024-10-10 09:43 UTC

This package is auto-updated.

Last update: 2024-11-10 10:03:16 UTC


README

This repository, besides the PHPCS LynxSolutionsCodingStandard, also includes configuration files for various static analysis tools used in LynxSolutions PHP(mostly Laravel) projects.

Installation

Composer:

composer require --dev lynxsolutions/php-static-analysis

Usage

PHP_CodeSniffer:

In your project's phpcs.xml file add the following line:

<rule ref="LynxSolutionsCodingStandard"/>

If you don't have a phpcs.xml file, here's a simple example:

<?xml version="1.0"?>
<ruleset
        name="LynxSolutions PHPCS default configuration"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
    <description>LynxSolutions PHPCS default configuration.</description>
    
    <arg name="extensions" value="php"/>
    <arg name="colors" />

    <arg value="sp"/>

    <file>app</file>
    <file>bootstrap</file>
    <file>config</file>
    <file>database</file>
    <file>routes</file>
    <file>tests</file>

    <exclude-pattern>cache/*</exclude-pattern>

    <rule ref="LynxSolutionsCodingStandard"/>
</ruleset>

Now you should be able to run:

vendor/bin/phpcs

PHP Mess Detector:

In your project's phpmd.xml file add the following line:

<rule ref="vendor/lynxsolutions/php-static-analysis/phpmd/phpmd.xml"/>

If you don't have a phpmd.xml file, here's a simple example:

<?xml version="1.0"?>
<ruleset
    name="LynxSolutions PHPMD default configuration"
    xmlns="http://pmd.sf.net/ruleset/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
    <description>LynxSolutions PHPMD default configuration.</description>

    <rule ref="vendor/lynxsolutions/php-static-analysis/phpmd/phpmd.xml"/>
</ruleset>

Now you can run:

vendor/bin/phpmd app,bootstrap,config,database,routes,tests text phpmd.xml

PHPStan:

In your project's phpstan.neon file add the following line:

includes:
    - vendor/lynxsolutions/php-static-analysis/phpstan/phpstan.neon

For Laravel projects:

First, make sure you install the larastan/larastan package:

composer require --dev larastan/larastan

Then, in your project's phpstan.neon, include the following:

includes:
    - vendor/lynxsolutions/php-static-analysis/phpstan/laravel.neon

If you don't have a phpstan.neon file, here's a simple example:

includes:
    - vendor/lynxsolutions/php-static-analysis/phpstan/laravel.neon

parameters:
    paths:
        - app
        - bootstrap
        - config
        - database
        - routes
        - tests

Now you can run:

vendor/bin/phpstan analyse