These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\SchemaOrg\Generator\Writer; |
||
4 | |||
5 | use League\Flysystem\Adapter\Local; |
||
6 | use Spatie\SchemaOrg\Generator\Type; |
||
7 | use League\Flysystem\Filesystem as Flysystem; |
||
8 | use Spatie\SchemaOrg\Generator\TypeCollection; |
||
9 | |||
10 | class Filesystem |
||
11 | { |
||
12 | /** @var \League\Flysystem\Filesystem */ |
||
13 | protected $flysystem; |
||
14 | |||
15 | /** @var \Spatie\SchemaOrg\Generator\Writer\Template */ |
||
16 | protected $typeTemplate; |
||
17 | |||
18 | public function __construct(string $root) |
||
19 | { |
||
20 | $adapter = new Local($root); |
||
21 | $this->flysystem = new Flysystem($adapter); |
||
22 | |||
23 | $this->typeTemplate = new Template('Type.php.twig'); |
||
24 | $this->builderClassTemplate = new Template('Schema.php.twig'); |
||
0 ignored issues
–
show
|
|||
25 | } |
||
26 | |||
27 | public function clear() |
||
28 | { |
||
29 | $this->flysystem->deleteDir('src'); |
||
30 | $this->flysystem->createDir('src'); |
||
31 | } |
||
32 | |||
33 | public function cloneStaticFiles() |
||
34 | { |
||
35 | $files = $this->flysystem->listContents('generator/templates/static', true); |
||
36 | |||
37 | foreach ($files as $file) { |
||
38 | if ($file['type'] !== 'file') { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | $this->flysystem->put( |
||
43 | str_replace('generator/templates/static', 'src', $file['path']), |
||
44 | $this->flysystem->read($file['path']) |
||
0 ignored issues
–
show
|
|||
45 | ); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | public function createType(Type $type) |
||
50 | { |
||
51 | $this->flysystem->put( |
||
52 | "src/{$type->name}.php", |
||
53 | $this->typeTemplate->render(['type' => $type]) |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | public function createBuilderClass(TypeCollection $types) |
||
58 | { |
||
59 | $this->flysystem->put( |
||
60 | 'src/Schema.php', |
||
61 | $this->builderClassTemplate->render(['types' => $types->toArray()]) |
||
62 | ); |
||
63 | } |
||
64 | } |
||
65 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: