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.

SearchService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 35
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTranslatableStrings() 0 18 3
A getFiles() 0 13 2
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
Bug introduced by
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