for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Intersvyaz\AssetManager;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Yii;
class FileSystemHash implements FileSystemHashInterface
{
/**
* @inheritdoc
*/
public function hashPath($path)
$path = realpath($path);
$hashes = [];
if (is_dir($path)) {
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
/** @var SplFileInfo $file */
foreach ($it as $file) {
if ($file->isFile()) {
$hashes[] = md5_file($file);
}
if (empty($hashes)) {
$hashes[] = $this->hashPathName($path);
} else {
sort($hashes);
$hashes[] = md5_file($path);
return md5(implode($hashes, '|'));
'|'
string
array
$pieces
implode()
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
ignore-type
return md5(implode($hashes, /** @scrutinizer ignore-type */ '|'));
public function hashPathName($path)
$hashPath = str_replace(Yii::getAlias('@app'), '', $path);
if (DIRECTORY_SEPARATOR === '\\') {
$hashPath = str_replace(DIRECTORY_SEPARATOR, '/', $hashPath);
return md5($hashPath);