GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (11)

src/SearchService.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProcyonWeb\TranslationGenerator;
6
7
use Illuminate\Support\Collection;
8
9
class SearchService
10
{
11
    public function getTranslatableStrings(array $patterns): array
12
    {
13
        $translations = [];
14
        $files = $this->getFiles($patterns);
15
16
        foreach ($files as $file) {
17
            $handle = fopen($file, 'rb');
18
            $text = fread($handle, filesize($file));
0 ignored issues
show
It seems like $handle can also be of type false; however, parameter $handle of fread() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
            $text = fread(/** @scrutinizer ignore-type */ $handle, filesize($file));
Loading history...
19
20
            $re = '/(?:\_\_|\$t)\(\\\'((?:.(?!(?<![\\\\])\\\'))*.?)/m';
21
            preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0);
22
23
            foreach ($matches as $match) {
24
                $translations[] = $match[1];
25
            }
26
        }
27
28
        return array_unique($translations);
29
    }
30
31
    public function getFiles(array $patterns): Collection
32
    {
33
        $files = new Collection();
34
35
        foreach ($patterns as $path => $pattern) {
36
            $directory = new \RecursiveDirectoryIterator($path);
37
            $iterator = new \RecursiveIteratorIterator($directory);
38
            $regexIterator = new \RegexIterator($iterator, $pattern, \RecursiveRegexIterator::GET_MATCH);
39
            $fileArray = new Collection(iterator_to_array($regexIterator));
40
            $files = $files->merge($fileArray->flatten());
41
        }
42
43
        return $files;
44
    }
45
}
46