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

wol-soft / php-json-schema-model-generator / 26374741919

24 May 2026 10:39PM UTC coverage: 98.638% (+0.08%) from 98.554%
26374741919

Pull #135

github

web-flow
Merge 95246e9e8 into cf5b7af2c
Pull Request #135: Boolean schemas

385 of 388 new or added lines in 16 files covered. (99.23%)

2 existing lines in 2 files now uncovered.

5141 of 5212 relevant lines covered (98.64%)

633.12 hits per line

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

95.65
/src/SchemaProvider/RecursiveDirectoryProvider.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\SchemaProvider;
6

7
use PHPModelGenerator\Exception\FileSystemException;
8
use PHPModelGenerator\Exception\SchemaException;
9
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
10
use RecursiveDirectoryIterator;
11
use RecursiveIteratorIterator;
12
use RegexIterator;
13

14
/**
15
 * Class RecursiveDirectoryProvider
16
 *
17
 * @package PHPModelGenerator\SchemaProvider
18
 */
19
class RecursiveDirectoryProvider implements SchemaProviderInterface
20
{
21
    use RefResolverTrait;
22

23
    private string $sourceDirectory;
24

25
    /**
26
     * RecursiveDirectoryProvider constructor.
27
     *
28
     * @throws FileSystemException
29
     */
30
    public function __construct(string $sourceDirectory)
2,457✔
31
    {
32
        if (!is_dir($sourceDirectory)) {
2,457✔
33
            throw new FileSystemException("Source directory '$sourceDirectory' doesn't exist");
1✔
34
        }
35

36
        $this->sourceDirectory = realpath(rtrim($sourceDirectory, "\\/")) ?: rtrim($sourceDirectory, "\\/");
2,456✔
37
    }
38

39
    /**
40
     * @inheritDoc
41
     *
42
     * @throws SchemaException
43
     */
44
    public function getSchemas(): iterable
2,435✔
45
    {
46
        $directory = new RecursiveDirectoryIterator($this->sourceDirectory);
2,435✔
47
        $iterator = new RecursiveIteratorIterator($directory);
2,435✔
48
        $schemaFiles = [];
2,435✔
49

50
        foreach (new RegexIterator($iterator, '/^.+\.json$/i', RegexIterator::GET_MATCH) as $file) {
2,435✔
51
            $schemaFiles[] = $file[0];
2,435✔
52
        }
53

54
        sort($schemaFiles, SORT_REGULAR);
2,435✔
55
        foreach ($schemaFiles as $file) {
2,435✔
56
            $jsonSchema = file_get_contents($file);
2,435✔
57

58
            if (!$jsonSchema) {
2,435✔
UNCOV
59
                throw new SchemaException("Invalid JSON-Schema file $file");
×
60
            }
61

62
            $decodedJsonSchema = json_decode($jsonSchema, true);
2,435✔
63

64
            if (json_last_error() !== JSON_ERROR_NONE) {
2,435✔
65
                throw new SchemaException("Invalid JSON-Schema file $file");
1✔
66
            }
67

68
            if (!is_array($decodedJsonSchema)) {
2,434✔
69
                continue;
1✔
70
            }
71

72
            yield new JsonSchema($file, $decodedJsonSchema);
2,434✔
73
        }
74
    }
75

76
    /**
77
     * @inheritDoc
78
     */
79
    public function getBaseDirectory(): string
2,434✔
80
    {
81
        return $this->sourceDirectory;
2,434✔
82
    }
83
}
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