Coder Social home page Coder Social logo

php-dev-tools's Introduction

PrestaShop Coding Standards

Latest Stable Version Minimum PHP Version Quality Control Status

This repository includes tools to check that repositories are following the standards defined by the PrestaShop community and provides configuration files for some of them.

Related packages:

Installation

composer require --dev prestashop/php-dev-tools

When this project is successfully added to your dependencies, you can enable each review tool on your projet.

Version Guidance

Version Status Packagist - Namespace Repo Docs PHP Version
1.x EOL prestashop/php-dev-tools N/A v1.x N/A >=5.6,<7.2
2.x EOL prestashop/php-dev-tools N/A v2.x N/A >=5.6,<7.2
3.x Security fixes prestashop/php-dev-tools N/A v3.x N/A >=5.6,>=7.2.5
4.x Latest prestashop/php-dev-tools N/A v4.x N/A >=7.2.5

PHP Cs fixer

$ php vendor/bin/prestashop-coding-standards cs-fixer:init [--dest /path/to/my/project]

It'll create a configuration file .php-cs-fixer.dist.php in the root of your project.

Upgrade note : When upgrading from 4.1.0 to newer version, you should re-run the init script or rename your .php_cs.dist file to .php-cs-fixer.dist.php in order to match the new requirements of cs-fixer.

Phpstan

$ php vendor/bin/prestashop-coding-standards phpstan:init [--dest /path/to/my/project]

It'll create a default file phpstan.neon in tests/phpstan, that are required to run phpstan. The default phpstan level is the lowest available, but we recommend you to update this value to get more recommandations.

PHPStan is not provided by our dependencies, because of the PHP compatibility from projects using this repository. We recommend you to install it globally on your environment:

composer global require phpstan/phpstan:^0.12

Usage

The configuration files added in your project can be freely modified in order to match your needs.

Running the tools can be done by calling its binary:

PHP CS Fixer

$ vendor/bin/php-cs-fixer fix

PHPStan

If you have installed PHPStan globally and made the folder available in your PATH:

$ _PS_ROOT_DIR_=<Path_to_PrestaShop> phpstan --configuration=tests/phpstan/phpstan.neon analyse <path1 [path2 [...]]>

Otherwise, you can specify the path to the PHPStan binary. For instance:

$ _PS_ROOT_DIR_=<Path_to_PrestaShop> php ~/.composer/vendor/bin/phpstan.phar --configuration=tests/phpstan/phpstan.neon analyse <path1 [path2 [...]]>

Autoindex

Applying an index.php file to all your project subfolders will be useful to avoid directories to be listed by the webserver.

$ vendor/bin/autoindex prestashop:add:index <path>

Header Stamp

Your license headers can be updated by applying the header stamp.

Here is an example of call, applying the default license on a PrestaShop module:

$ vendor/bin/header-stamp --license=assets/afl.txt --exclude=vendor,node_modules

Available options are provided with --help.

php-dev-tools's People

Contributors

ajenbo avatar hugofintecture avatar intraordinaire avatar jmcollin avatar kpodemski avatar m-poulain avatar madsoliver avatar matks avatar nicosomb avatar pierrerambaud avatar prestasafe avatar progi1984 avatar quetzacoalt91 avatar sebsept avatar touxten avatar zalexki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-dev-tools's Issues

Improve maintenability of bootstrap.php (phpstan)

Everytime we modify the file bootstrap.php, we need to update it in the by copy pasting it in all projects using our configuration file.

As that file is never modified for a specific project, the best thing would be to load it directly from the foldervendor/prestashop/php-dev-tools/ when running phpstan.

Consider renaming this project

This project won't provide tools only for coding standards, the current name php-coding-standards seems too restrictive.

Prestashop: FatalThrowableError after installing the dev tools

Hello,

I got this error after installing this package and run composer dump-autoload

If I run composer dump-autoload --no-dev it's fine, but the package is not loaded.

(1/1) FatalThrowableError
Type error: Argument 1 passed to Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher::dispatch() must be an object, string given, called in /Users/gkssjovi/www/prestashop/prestashop_1.7.5.0/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php on line 127

command 'phpstan:init' should not return 0 when file not overriden

Use case :

  • the command is invoked from a script (external symfony command for example), in non-interactive mode (interactive mode is not possible in this context)
  • phpstan.neon file already exists

Was the command successful ? I think not, the new file was not copied/installed, we can't consider the init process is a success.
So in this case, command should return 1 or another code maybe 2, but not 0. (2 or more is best option I suppose).

Furthermore, there is another argument for arguing that the command should return 1.
Because of the non possible interaction, symfony has started to fill the errorOutput content, which means that symfony considers that an error happend. ($installPhpStanConfiguration->getErrorOutput() has content, see below).

Example :

$this->io->write("Installation of {$this->getScriptName()} configuration file : ", false);
$installPhpStanConfiguration = new Process(['php', 'vendor/bin/prestashop-coding-standards', 'phpstan:init', '--dest', getcwd()]);
$installPhpStanConfiguration->start();
$installPhpStanConfiguration->wait();

 if (!$installPhpStanConfiguration->isSuccessful()) {
            $this->io->error('failed !');
            throw new RuntimeException("{$this->getPackageName()} configuration : {$installPhpStanConfiguration->getErrorOutput()}");
        }
// The process is reported to successful even if the new file was not written :( 
// fun fact : isSuccessuf() is true but getErrorOutput() has content
// at this point, we should parse the getErrorOutput()  content to guess if an error happened.

symfony/event-dispatcher must be downgraded

Actually, if we install this dependency in module, that installs symfony/event-dispatcher in version 5.0.

But PrestaShop embed symfony/event-dispatcher in 3.4

And that broke modules as install :

image

image

Define constants when supposed to be existing in core

Some of the constants have been created from a version of PS after 1.6.0.0, and the current module developers aim a compatibility with all PS 1.6 & 1.7. For instance, _PS_PRICE_COMPUTE_PRECISION_ exists from PS 1.6.0.11 (PrestaShop/PrestaShop-1.6@3ef7573).

To avoid modules using these constants when not defined, we must make sure the error is properly reported by not defining these constant when the running PrestaShop version is older. This would avoid PHP errors being triggered once the modules pushed to production.

Whitespace after file header

PrestaShop modules validator want that there is one empty line between file header and next statement:

/**
 * Here is license...
 */

if (!defined('_PS_VERSION_')) {
    exit;
}

but config provided by php-dev-tools removes this newline.

Lot of "Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__'

When running the phpstan command I got a lot of this errors.
This is not critical on my machine but fails on CI (see below).

/home/http/tests/phpstan-prestashop/blockreassurance(dev*) » _PS_ROOT_DIR_=/home/http/tests/prestashop/ps1771 ./phpstan.phar analyse ./                                         seb@localhost
Note: Using configuration file /home/http/tests/phpstan-prestashop/blockreassurance/phpstan.neon.
PHP Warning:  Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 29

Warning: Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 29
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 30

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 30
PHP Warning:  Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 30

Warning: Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 30
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 39

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 39
PHP Warning:  Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 40

Warning: Use of undefined constant _THEME_NAME_ - assumed '_THEME_NAME_' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 40
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 46

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 46
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 61

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 61
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 62

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 62
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 63

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 63
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 64

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 64
PHP Warning:  Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 65

Warning: Use of undefined constant __PS_BASE_URI__ - assumed '__PS_BASE_URI__' (this will throw an Error in a future version of PHP) in /home/http/tests/prestashop/ps1771/config/defines_uri.inc.php on line 65
Detected PS version 1.7.7.1
 35/35 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -------------------------------------------------------------------------------------------------------------------------------------- 
  Line   blockreassurance.php                                                                                                                  
 ------ -------------------------------------------------------------------------------------------------------------------------------------- 
  247    Method blockreassurance::loadAsset() has no return typehint specified.  
....

Cannot execute phpstan because of phpstan-shim

Hi,

When I execute vendor/bin/phpstan analyse .:

$ php7.4 vendor/bin/phpstan analyse .

Thank you for using PHPStan!

With the release of PHPStan 0.12, the primary Composer package used by most users,
phpstan/phpstan, has switched to a PHAR file. It works the same way as phpstan-shim.
The need for a separate PHAR distribution has ceased.
Package phpstan/phpstan-shim is no longer needed.

You should upgrade to phpstan/phpstan 0.12 with the following steps:
1) In your composer.json, rewrite line with "phpstan/phpstan-shim"
   to "phpstan/phpstan": "^0.12".
2) Delete your composer.lock.
3) Delete vendor/phpstan directory.
4) Delete vendor/bin/phpstan and vendor/bin/phpstan.phar.
5) Run composer install.

If you have any problem upgrading, don't hesitate to describe your issue at:
https://github.com/phpstan/phpstan/issues/new/choose

I cannot remove this because it's in prestashop/php-dev-tools dependencies.

A way to update the dependency?

initial phpstan.neon is bugged

Executing php vendor/bin/prestashop-coding-standards phpstan:init [--dest /path/to/my/project] as written on the Readme.md creates a default phpstan.neon file.

It has 2 problems :

  1. Path to extension is wrong
  2. exclude vendor is missing (not really a bug but a major improvement to get started).

Problem 1 : wrong path to extension

This cause this error :

» _PS_ROOT_DIR_=/home/http/tests/prestashop/ps1771 ./phpstan.phar analyse
Note: Using configuration file /home/http/tests/phpstan-prestashop/blockreassurance/phpstan.neon.
File '/home/http/tests/phpstan-prestashop/blockreassurance/vendor/prestashop/php-dev-tools/phpstan/extension.neon' is missing or is not readable.

After fixing this the first run is very long because it parses the vendor directory.

  1. Exclude vendor folder from analyse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.