20 'jpg',
'jpeg',
'png',
'gif',
'swf',
'mp3',
'avi',
'mov',
'flv',
'jar',
'zip',
21 'eot',
'ttf',
'woff',
'woff2',
'ico',
'svg',
51 'lib/web/legacy-build.min.js' 94 private $exclude = [];
106 throw new \Magento\TestFramework\Inspection\Exception(
"Base directory {$baseDir} does not exist");
108 $this->_baseDir = str_replace(
'\\',
'/', realpath(
$baseDir));
112 if (!is_array($configFiles)) {
113 $configFiles = [$configFiles];
115 foreach ($configFiles as $configFile) {
120 foreach ($configFiles as $configFile) {
121 $configFile = str_replace(
'\\',
'/', realpath($configFile));
122 $this->_whitelist[$configFile] = [];
128 if (!$this->_words) {
129 throw new \Magento\TestFramework\Inspection\Exception(
'No words to check');
143 if (!file_exists($configFile)) {
144 throw new \Magento\TestFramework\Inspection\Exception(
"Configuration file {$configFile} does not exist");
149 throw new \Magento\TestFramework\Inspection\Exception($e->getMessage(), $e->getCode(), $e);
165 $nodes = $configXml->xpath(
'//config/words/word');
166 foreach ($nodes as $node) {
167 $words[] = (string)$node;
169 $words = array_filter($words);
171 $words = array_merge($this->_words, $words);
172 $this->_words = array_unique($words);
190 $nodes = $configXml->xpath(
'//config/whitelist/item');
191 foreach ($nodes as $node) {
192 $path = $node->xpath(
'path');
194 throw new \Magento\TestFramework\Inspection\Exception(
195 'A "path" must be defined for the whitelisted item' 198 $component = $node->xpath(
'component');
200 $componentType = $component[0]->xpath(
'@type')[0];
201 $componentName = $component[0]->xpath(
'@name')[0];
202 $path = $this->componentRegistrar->getPath((
string)$componentType, (
string)$componentName)
203 .
'/' . (string)
$path[0];
205 $path = $this->_baseDir .
'/' . (string)
$path[0];
210 $wordNodes = $node->xpath(
'word');
212 foreach ($wordNodes as $wordNode) {
213 $words[] = (string)$wordNode;
216 $whitelist[
$path] = $words;
218 $excludeNodes = $node->xpath(
'exclude');
221 foreach ($excludeNodes as $extractNode) {
222 $excludes[] = (string)$extractNode;
226 if (isset($exclude[
$path])) {
227 $exclude[
$path] = array_merge($excludes, $exclude[
$path]);
229 $exclude[
$path] = $excludes;
234 foreach ($whitelist as $newPath => $newWords) {
235 if (isset($this->_whitelist[$newPath])) {
236 $newWords = array_merge($this->_whitelist[$newPath], $newWords);
238 $this->_whitelist[$newPath] = array_unique($newWords);
241 foreach ($exclude as $newPath => $newWords) {
242 if (isset($this->exclude[$newPath])) {
243 $newWords = array_merge($this->exclude[$newPath], $newWords);
245 $this->exclude[$newPath] = array_unique($newWords);
256 $this->_whitelist = [];
257 foreach ($whitelist as $whitelistFile => $whitelistWords) {
258 $whitelistFile = str_replace(
'\\',
'/', $whitelistFile);
259 $this->_whitelist[$whitelistFile] = $whitelistWords;
293 if (isset($this->exclude[$file]) && !empty($this->exclude[$file])) {
294 foreach ($this->exclude[$file] as $stringToEliminate) {
300 foreach ($this->_words as $word) {
301 if (stripos(
$path, $word) !==
false || stripos(
$contents, $word) !==
false) {
302 $foundWords[] = $word;
306 && (($copyrightStringPosition = mb_strpos(
$contents, $this->copyrightString)) ===
false 307 || ($copyingStringPosition = strpos(
$contents, $this->copyingString)) ===
false 308 || $copyingStringPosition - $copyrightStringPosition - mb_strlen($this->copyrightString) > 10)
310 $foundWords[] =
'Copyright string is missing';
321 if (in_array(pathinfo(
$path, PATHINFO_EXTENSION), $this->copyrightSkipExtensions)) {
324 foreach ($this->copyrightSkipList as $dir) {
325 if (strpos(
$path, $dir) !==
false) {
340 return in_array(pathinfo($file, PATHINFO_EXTENSION), $this->_binaryExtensions);
353 foreach ($this->_whitelist as $whitelistPath => $whitelistWords) {
354 if (strncmp($whitelistPath,
$path, strlen($whitelistPath)) != 0) {
358 if (!$whitelistWords) {
362 $foundWords = array_diff($foundWords, $whitelistWords);
375 if (strpos($file, $this->_baseDir) ===
false) {
378 return substr($file, strlen($this->_baseDir) + 1);
_removeWhitelistedWords($path, $foundWords)
__construct($configFiles, $baseDir, $componentRegistrar, $isCopyrightChecked=false)
_normalizeWhitelistPaths()
_extractWhitelist(\SimpleXMLElement $configXml)
isCopyrightCheckSkipped($path)
_extractWords(\SimpleXMLElement $configXml)