Download project

This commit is contained in:
Roman Pyrih
2024-11-20 09:09:44 +01:00
parent 547a138d6a
commit 5ff041757f
40737 changed files with 7766183 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 PrestaShop
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,107 @@
# PrestaShop Coding Standards
[![Latest Stable Version](https://img.shields.io/packagist/v/prestashop/php-dev-tools.svg?style=flat-square)](https://packagist.org/packages/prestashop/php-dev-tools) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2.5-8892BF.svg?style=flat-square)](https://php.net/) [![Quality Control Status](https://img.shields.io/github/workflow/status/prestashop/php-dev-tools/PHP%20tests?style=flat-square)](https://github.com/prestashop/php-dev-tools/actions/workflows/php.yml)
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:
* [friendsofphp/php-cs-fixer](http://github.com/FriendsOfPHP/PHP-CS-Fixer)
* [phpstan/phpstan](https://github.com/phpstan/phpstan)
* [prestashop/autoindex](https://github.com/PrestaShopCorp/autoindex)
* [prestashop/header-stamp](https://github.com/PrestaShopCorp/header-stamp)
## 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][lib-1-repo] | N/A | >=5.6,<7.2 |
| 2.x | EOL | `prestashop/php-dev-tools` | N/A | [v2.x][lib-2-repo] | N/A | >=5.6,<7.2 |
| 3.x | Security fixes | `prestashop/php-dev-tools` | N/A | [v3.x][lib-3-repo] | N/A | >=5.6,>=7.2.5 |
| 4.x | Latest | `prestashop/php-dev-tools` | N/A | [v4.x][lib-4-repo] | N/A | >=7.2.5 |
[lib-1-repo]: https://github.com/PrestaShop/php-dev-tools/tree/1.x
[lib-2-repo]: https://github.com/PrestaShop/php-dev-tools/tree/2.x
[lib-3-repo]: https://github.com/PrestaShop/php-dev-tools/tree/3.x
[lib-4-repo]: https://github.com/PrestaShop/php-dev-tools/tree/master
### PHP Cs fixer
```bash
$ 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
```bash
$ 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
```bash
$ vendor/bin/php-cs-fixer fix
```
### PHPStan
If you have installed PHPStan globally and made the folder available in your PATH:
```php
$ _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:
```php
$ _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.
```php
$ vendor/bin/autoindex
```
### 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:
```php
$ vendor/bin/header-stamp --license=assets/afl.txt --exclude=vendor,node_modules
```
Available options are provided with `--help`.

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5;
// OK, it's not, let give Composer autoloader a try!
$autoloadFile = __DIR__ . '/../../../autoload.php';
if (\file_exists($autoloadFile)) {
require_once $autoloadFile;
} else {
require_once __DIR__ . '/../vendor/autoload.php';
}
use Symfony\Component\Console\Application;
use ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\Command\CsFixerInitCommand;
use ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\Command\PhpStanInitCommand;
$app = new Application();
$app->add(new CsFixerInitCommand());
$app->add(new PhpStanInitCommand());
$app->run();

View File

@@ -0,0 +1,28 @@
{
"name": "prestashop\/php-dev-tools",
"description": "PrestaShop coding standards",
"license": "MIT",
"require": {
"php": ">=7.2.5",
"symfony\/console": "~3.2 || ~4.0 || ~5.0 || ~6.0",
"friendsofphp\/php-cs-fixer": "^3.2",
"squizlabs\/php_codesniffer": "^3.4",
"symfony\/filesystem": "~3.2 || ~4.0 || ~5.0 || ~6.0",
"prestashop\/header-stamp": "^2.0",
"prestashop\/autoindex": "^2.0"
},
"bin": [
"bin\/prestashop-coding-standards"
],
"autoload": {
"psr-4": {
"ps_metrics_module_v4_0_5\\PrestaShop\\CodingStandards\\": "src\/"
}
},
"config": {
"platform": {
"php": "7.2.5"
}
},
"author": "PrestaShop"
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,102 @@
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5;
function requireFileIfItExists(string $filepath) : bool
{
if (\file_exists($filepath)) {
require_once $filepath;
return \true;
}
return \false;
}
$rootDir = \getenv('_PS_ROOT_DIR_');
if (!$rootDir) {
echo '[ERROR] Define _PS_ROOT_DIR_ with the path to PrestaShop folder' . \PHP_EOL;
exit(1);
}
if (!\realpath($rootDir)) {
echo \sprintf('[ERROR] _PS_ROOT_DIR_ configuration is wrong. No directory found at %s .', $rootDir) . \PHP_EOL;
exit(1);
}
// This file will be in the directory vendor/prestashop/php-dev-tools/phpstan.
$pathToModuleRoot = __DIR__ . '/../../../../';
// Add module composer autoloader
require_once \realpath(__DIR__ . '/../../../autoload.php');
// Add PrestaShop composer autoload
\define('_PS_ADMIN_DIR_', $rootDir . '/admin-dev/');
\define('PS_ADMIN_DIR', \_PS_ADMIN_DIR_);
\define('__PS_BASE_URI__', '/');
\define('_THEME_NAME_', 'default-bootstrap');
requireFileIfItExists($rootDir . '/tools/smarty/Smarty.class.php');
requireFileIfItExists($rootDir . '/config/defines.inc.php');
requireFileIfItExists($rootDir . '/config/autoload.php');
requireFileIfItExists($rootDir . '/config/defines_uri.inc.php');
requireFileIfItExists($rootDir . '/config/bootstrap.php');
// Make sure loader php-parser is coming from php stan composer
// 1- Use module vendors
$loader = new \ps_metrics_module_v4_0_5\Composer\Autoload\ClassLoader();
$loader->setPsr4('PhpParser\\', ['vendor/nikic/php-parser/lib/PhpParser']);
$loader->register(\true);
// 2- Use with Docker container
$loader = new \ps_metrics_module_v4_0_5\Composer\Autoload\ClassLoader();
$loader->setPsr4('PhpParser\\', ['/composer/vendor/nikic/php-parser/lib/PhpParser']);
$loader->register(\true);
// 3- Use with PHPStan phar
$loader = new \ps_metrics_module_v4_0_5\Composer\Autoload\ClassLoader();
// Contains the vendor in phar, like "phar://phpstan.phar/vendor"
$loader->setPsr4('PhpParser\\', ['phar://' . \dirname($_SERVER['PATH_TRANSLATED']) . '/../phpstan/phpstan-shim/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/']);
$loader->register(\true);
// 4- Use phpstan phar with sym link
$loader = new \ps_metrics_module_v4_0_5\Composer\Autoload\ClassLoader();
$loader->setPsr4('PhpParser\\', ['phar://' . \realpath($_SERVER['PATH_TRANSLATED']) . '/vendor/nikic/php-parser/lib/PhpParser/']);
$loader->register(\true);
/*
* At this time if _PS_VERSION_ is still undefined, this is likely because
* - we are on a old PrestaShop (below 1.7.0.0),
* - and the shop hasn't been installed yet.
*
* In that case, the constant can be set from another file in the installation folder.
*/
if (!\defined('_PS_VERSION_')) {
$legacyInstallationFileDefiningConstant = ['/install-dev/install_version.php', '/install/install_version.php'];
foreach ($legacyInstallationFileDefiningConstant as $file) {
if (requireFileIfItExists($rootDir . $file)) {
\define('_PS_VERSION_', \_PS_INSTALL_VERSION_);
break;
}
}
}
/*
* Display version of PrestaShop, useful for debug
*/
if (\defined('_PS_VERSION_')) {
echo 'Detected PS version ' . \_PS_VERSION_ . \PHP_EOL;
}
// We must declare these constant in this boostrap script.
// Ignoring the error partern with this value will throw another error if not found
// during the checks.
$constantsToDefine = ['_DB_SERVER_' => ['type' => 'string'], '_DB_NAME_' => ['type' => 'string'], '_DB_USER_' => ['type' => 'string'], '_DB_PASSWD_' => ['type' => 'string'], '_MYSQL_ENGINE_' => ['type' => 'string'], '_COOKIE_KEY_' => ['type' => 'string'], '_COOKIE_IV_' => ['type' => 'string'], '_DB_PREFIX_' => ['type' => 'string'], '_PS_SSL_PORT_' => ['type' => 'int'], '_THEME_COL_DIR_' => ['type' => 'string'], '_PARENT_THEME_NAME_' => ['type' => 'string'], '_PS_PRICE_DISPLAY_PRECISION_' => ['type' => 'int'], '_PS_PRICE_COMPUTE_PRECISION_' => ['type' => 'string', 'from' => '1.6.0.11'], '_PS_OS_CHEQUE_' => ['type' => 'int'], '_PS_OS_PAYMENT_' => ['type' => 'int'], '_PS_OS_PREPARATION_' => ['type' => 'int'], '_PS_OS_SHIPPING_' => ['type' => 'int'], '_PS_OS_DELIVERED_' => ['type' => 'int'], '_PS_OS_CANCELED_' => ['type' => 'int'], '_PS_OS_REFUND_' => ['type' => 'int'], '_PS_OS_ERROR_' => ['type' => 'int'], '_PS_OS_OUTOFSTOCK_' => ['type' => 'int'], '_PS_OS_OUTOFSTOCK_PAID_' => ['type' => 'int'], '_PS_OS_OUTOFSTOCK_UNPAID_' => ['type' => 'int'], '_PS_OS_BANKWIRE_' => ['type' => 'int'], '_PS_OS_PAYPAL_' => ['type' => 'int'], '_PS_OS_WS_PAYMENT_' => ['type' => 'int'], '_PS_OS_COD_VALIDATION_' => ['type' => 'int'], '_PS_THEME_DIR_' => ['type' => 'string'], '_PS_BASE_URL_' => ['type' => 'string'], '_MODULE_DIR_' => ['type' => 'string']];
foreach ($constantsToDefine as $key => $constantDetails) {
// If already defined, continue
if (\defined($key)) {
continue;
}
// Some constants exist from a specific version of PrestaShop.
// If the running PS version is below the one that created this constant, we pass.
if (!empty($constantDetails['from']) && \defined('_PS_VERSION_') && \version_compare(\_PS_VERSION_, $constantDetails['from'], '<')) {
continue;
}
switch ($constantDetails['type']) {
case 'string':
\define($key, 'DUMMY_VALUE');
break;
case 'int':
\define($key, 1);
break;
default:
\define($key, 'DUMMY_VALUE');
break;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,9 @@
parameters:
bootstrapFiles:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/bootstrap.php
stubFiles:
- stubs/Module.stub
- stubs/Tab.stub
dynamicConstantNames:
- _PS_VERSION_
- _PS_MODE_DEV_

View File

@@ -0,0 +1,39 @@
<?php
namespace PrestaShop\PrestaShop\Core\Module {
interface ModuleInterface
{
}
}
namespace {
class Module extends ModuleCore
{
}
use PrestaShop\PrestaShop\Core\Module\ModuleInterface;
/**
* Missing properties:
* @property string $module_key
* @property bool $bootstrap
* @property string $confirmUninstall
*/
abstract class ModuleCore implements ModuleInterface
{
/** @var string */
public $version;
/**
* Return type was wrong until 1.7.7.0
* https://github.com/PrestaShop/PrestaShop/commit/9a8144a15d21e3fdcde3e2a703de3339be6e8295
*
* @param string $module_name Module name
*
* @return self|false
*/
public static function getInstanceByName($module_name) {}
}
}

View File

@@ -0,0 +1,23 @@
<?php
class Tab extends TabCore
{
}
class ObjectModel
{
}
/**
* Wrong properties:
* @property string|array<string> $name
* @property bool $active
*/
class TabCore extends ObjectModel
{
/** @var string|array<string> Displayed name */
public $name;
/** @var bool active */
public $active = true;
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,65 @@
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Filesystem\Filesystem;
abstract class AbstractCommand extends Command
{
/**
* Copy file, check if file exists.
* If yes, ask for overwrite
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $source
* @param string $destination
*/
protected function copyFile(InputInterface $input, OutputInterface $output, string $source, string $destination) : void
{
$fs = new Filesystem();
if ($fs->exists($destination) && !$this->askForOverwrite($input, $output, $source, $destination)) {
return;
}
$fs->copy($source, $destination);
$output->writeln(\sprintf('File "%s" copied to "%s"', \basename($source), $destination));
}
/**
* Ask for overwrite
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $source
* @param string $destination
* @param string $message
* @param bool $default
*
* @return bool
*/
protected function askForOverwrite(InputInterface $input, OutputInterface $output, string $source, string $destination, ?string $message = null, bool $default = \false) : bool
{
if (null === $message) {
$availableOptionsText = $default ? '[Y/n]' : '[y/N]';
$message = \sprintf('%s already exists in destination folder %s. Overwrite? %s ', \pathinfo($source, \PATHINFO_BASENAME), \pathinfo(\realpath($destination), \PATHINFO_DIRNAME), $availableOptionsText);
}
$helper = $this->getHelper('question');
$overwriteQuestion = new ConfirmationQuestion($message, $default);
return $helper->ask($input, $output, $overwriteQuestion);
}
/**
* Delete a file if exising
*
* @param string $filepath
*/
protected function deleteFile(string $filepath) : void
{
$fs = new Filesystem();
if ($fs->exists($filepath)) {
$fs->remove($filepath);
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CsFixerInitCommand extends AbstractCommand
{
protected function configure() : void
{
$this->setName('cs-fixer:init')->setDescription('Initialize Cs Fixer environement')->addOption('dest', null, InputOption::VALUE_REQUIRED, 'Where the configuration will be stored', '.');
}
protected function execute(InputInterface $input, OutputInterface $output) : int
{
$directory = __DIR__ . '/../../templates/cs-fixer/';
$destination = $input->getOption('dest');
// Try to delete the old dist file
$this->deleteFile($destination . '/.php_cs.dist');
// Create config file
foreach (['.php-cs-fixer.dist.php'] as $template) {
$this->copyFile($input, $output, $directory . $template, $destination . '/' . $template);
}
return 0;
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
class PhpStanInitCommand extends AbstractCommand
{
protected function configure() : void
{
$this->setName('phpstan:init')->setDescription('Initialize phpstan environement')->addOption('dest', null, InputOption::VALUE_REQUIRED, 'Where the configuration will be stored', 'tests/phpstan');
}
protected function execute(InputInterface $input, OutputInterface $output) : int
{
$fs = new Filesystem();
$directory = __DIR__ . '/../../templates/phpstan/';
$destination = $input->getOption('dest');
foreach (['phpstan.neon'] as $template) {
$this->copyFile($input, $output, $directory . $template, $destination . '/' . $template);
}
return 0;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,18 @@
<?php
declare (strict_types=1);
namespace ps_metrics_module_v4_0_5\PrestaShop\CodingStandards\CsFixer;
use ps_metrics_module_v4_0_5\PhpCsFixer\Config as BaseConfig;
class Config extends BaseConfig
{
public function __construct($name = 'default')
{
parent::__construct('PrestaShop coding standard');
$this->setRiskyAllowed(\true);
}
public function getRules() : array
{
return ['@Symfony' => \true, 'concat_space' => ['spacing' => 'one'], 'cast_spaces' => ['space' => 'single'], 'error_suppression' => ['mute_deprecation_error' => \false, 'noise_remaining_usages' => \false, 'noise_remaining_usages_exclude' => []], 'function_to_constant' => \false, 'visibility_required' => ['elements' => ['property', 'method']], 'no_alias_functions' => \false, 'phpdoc_summary' => \false, 'phpdoc_align' => ['align' => 'left'], 'protected_to_private' => \false, 'psr_autoloading' => \false, 'self_accessor' => \false, 'yoda_style' => \false, 'non_printable_character' => \true, 'no_superfluous_phpdoc_tags' => \false];
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,14 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
parameters:
paths:
- ./
excludes_analyse:
- vendor/
# We consider that the extension file will be stored the folder test/phpstan
# From Phpstan 0.12, paths are relative to the .neon file.
# - ../../classes
# - ../../controllers
reportUnmatchedIgnoredErrors: false
level: max

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,18 @@
{
"license": "MIT",
"require": {
"phpstan\/phpstan": "^0.12",
"prestashop\/php-dev-tools": "@dev"
},
"autoload": {
"classmap": [
"constant_check.php"
]
},
"repositories": [
{
"type": "path",
"url": "..\/..\/.."
}
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
<?php
namespace ps_metrics_module_v4_0_5;
class Constant_Check extends \Module
{
public function __construct()
{
$this->name = 'constants_check';
$this->tab = 'advertising_marketing';
$this->version = '1.0.0';
$this->author = 'PrestaShopCorp';
$this->need_instance = 0;
// This constant must trigger an error on PHPStan below PS 1.6.0.11
$value = \_PS_PRICE_COMPUTE_PRECISION_;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,9 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
parameters:
paths:
# We consider that the extension file will be stored the folder test/phpstan
# From Phpstan 0.12, paths are relative to the .neon file.
- constant_check.php
level: max

View File

@@ -0,0 +1,24 @@
#!/bin/bash
function runPHPStan {
echo "Running PHPStan with PS $1"
docker run -tid --rm -v ps-volume:/var/www/html --name test-ps prestashop/prestashop:$1
docker run --rm --volumes-from test-ps -v $PWD:/web/module -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan analyse --configuration=/web/module/phpstan.neon
result=$?
docker kill test-ps
docker volume rm ps-volume
if [ $result -ne $2 ]; then
echo "Expected result $2 does not match $result";
exit 1;
fi
}
composer install
# For copy of phpstan folder, in case we work on another branch locally
cp -R ../../../phpstan vendor/prestashop/php-dev-tools/
runPHPStan 1.7 0
runPHPStan 1.6.0.1 1

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;