Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CodeSniffer.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
21  private $rulesetDir;
22 
28  private $reportFile;
29 
35  private $wrapper;
36 
42  private $extensions = [
43  'php' => 'PHP',
44  'phtml' => 'PHP',
45  ];
46 
54  public function __construct($rulesetDir, $reportFile, Wrapper $wrapper)
55  {
56  $this->rulesetDir = $rulesetDir;
57  if (!file_exists($rulesetDir) && file_exists($fullPath = realpath(__DIR__ . '/../../../../' . $rulesetDir))) {
58  $this->rulesetDir = $fullPath;
59  }
60  $this->reportFile = $reportFile;
61  $this->wrapper = $wrapper;
62  }
63 
67  public function setExtensions(array $extensions)
68  {
69  $this->extensions = $extensions;
70  }
71 
77  public function canRun()
78  {
79  return class_exists('\PHP_CodeSniffer\Runner');
80  }
81 
85  public function run(array $whiteList)
86  {
87  if (empty($whiteList)) {
88  return 0;
89  }
90 
91  if (!defined('PHP_CODESNIFFER_IN_TESTS')) {
92  define('PHP_CODESNIFFER_IN_TESTS', true);
93  }
94 
95  $this->wrapper->checkRequirements();
96  $settings = [];
97  $settings['files'] = $whiteList;
98  $settings['standards'] = [$this->rulesetDir];
99  $settings['extensions'] = $this->extensions;
100  $settings['warningSeverity'] = 0;
101  $settings['reports']['full'] = $this->reportFile;
102  $this->wrapper->setSettings($settings);
103 
104  ob_start();
105  $result = $this->wrapper->runPHPCS();
106  ob_end_clean();
107 
108  return $result;
109  }
110 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$settings
Definition: bootstrap.php:29
__construct($rulesetDir, $reportFile, Wrapper $wrapper)
Definition: CodeSniffer.php:54