• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeTraceurSnorkLibrary / MessSaga / 23844646769

01 Apr 2026 10:42AM UTC coverage: 31.674% (+31.1%) from 0.549%
23844646769

push

github

web-flow
feat: media files import

431 of 801 new or added lines in 30 files covered. (53.81%)

4 existing lines in 4 files now uncovered.

439 of 1386 relevant lines covered (31.67%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/app/Services/Import/Export/Locators/ExportFile/AbstractExportFileLocator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Services\Import\Export\Locators\ExportFile;
6

7
/**
8
 * Базовая реализация finder'а с общей рекурсивной навигацией по дереву файлов.
9
 *
10
 * Наследники описывают только правила фильтрации нужного export-файла.
11
 */
12
abstract class AbstractExportFileLocator implements ExportFileLocatorInterface
13
{
14
    /**
15
     * @param string $absoluteDir
16
     * @param string $exactName
17
     *
18
     * @return string|null
19
     */
20
    protected function findExactName(string $absoluteDir, string $exactName): ?string
21
    {
22
        return $this->findRecursive(
2✔
23
            $absoluteDir,
2✔
24
            '',
2✔
25
            static fn(string $name): bool => strcasecmp($name, $exactName) === 0
2✔
26
        );
2✔
27
    }
28

29
    protected function findFirstByExtension(string $absoluteDir, string $extension): ?string
30
    {
31
        $normalizedExtension = '.' . ltrim(strtolower($extension), '.');
2✔
32

33
        return $this->findRecursive(
2✔
34
            $absoluteDir,
2✔
35
            '',
2✔
36
            static fn(string $name): bool => str_ends_with(strtolower($name), $normalizedExtension)
2✔
37
        );
2✔
38
    }
39

40
    protected function findFirstTxtContaining(string $absoluteDir, string $needle): ?string
41
    {
42
        $normalizedNeedle = strtolower($needle);
2✔
43

44
        return $this->findRecursive(
2✔
45
            $absoluteDir,
2✔
46
            '',
2✔
47
            static function (string $name) use ($normalizedNeedle): bool {
2✔
48
                $lower = strtolower($name);
2✔
49

50
                return str_ends_with($lower, '.txt') && str_contains($lower, $normalizedNeedle);
2✔
51
            }
2✔
52
        );
2✔
53
    }
54

55
    protected function findRecursive(string $absoluteDir, string $relativePrefix, callable $predicate): ?string
56
    {
57
        if (!is_dir($absoluteDir)) {
4✔
58
            return null;
1✔
59
        }
60

61
        $sep   = DIRECTORY_SEPARATOR;
3✔
62
        $items = @scandir($absoluteDir);
3✔
63
        if ($items === false) {
3✔
NEW
64
            return null;
×
65
        }
66

67
        foreach ($items as $item) {
3✔
68
            if ($item === '.' || $item === '..') {
3✔
69
                continue;
3✔
70
            }
71
            $full = $absoluteDir . $sep . $item;
3✔
72
            if (is_file($full) && $predicate($item)) {
3✔
73
                return $relativePrefix !== ''
3✔
74
                    ? $relativePrefix . '/' . $item
2✔
75
                    : $item;
3✔
76
            }
77
        }
78

79
        foreach ($items as $item) {
1✔
80
            if ($item === '.' || $item === '..') {
1✔
81
                continue;
1✔
82
            }
83
            $full = $absoluteDir . $sep . $item;
1✔
84
            if (is_dir($full)) {
1✔
85
                $prefix = $relativePrefix !== ''
1✔
86
                    ? $relativePrefix . '/' . $item
1✔
87
                    : $item;
1✔
88
                $found  = $this->findRecursive($full, $prefix, $predicate);
1✔
89
                if ($found !== null) {
1✔
90
                    return $found;
1✔
91
                }
92
            }
93
        }
94

NEW
95
        return null;
×
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc