SchemaPropertyWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 4
c 6
b 0
f 0
lcom 1
cbo 3
dl 0
loc 61
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A write() 0 55 4
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/18/15
5
 * Time: 10:46 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\SchemaOrg\Generator;
12
13
/**
14
 * Class SchemaPropertyWriter.
15
 */
16
class SchemaPropertyWriter extends SchemaWriter
17
{
18
    /**
19
     * @param SchemaRdfaData $schemaData
20
     */
21
    public function write(SchemaRdfaData $schemaData)
22
    {
23
        foreach ($schemaData->getProperties() as $property) {
24
            $className = $property['name'];
25
            $className[0] = strtoupper($className[0]);
26
27
            $allowed = [];
28
            foreach ($property['usedOnClass'] as $belongs) {
29
                if ('Type' === substr($belongs, -4)) {
30
                    $belongs = substr($belongs, 0, -4);
31
                }
32
33
                $allowed[] = "\t\t'".'http://schema.org/'.$belongs."'";
34
            }
35
            $allowed = implode(",\n", $allowed);
36
37
            $phpPropertyCode = <<<PHP
38
<?php
39
/**
40
 * Author: Nil Portugués Calderó <[email protected]>
41
 * Date: 12/18/15
42
 * Time: 11:36 PM.
43
 *
44
 * For the full copyright and license information, please view the LICENSE
45
 * file that was distributed with this source code.
46
 */
47
48
namespace NilPortugues\SchemaOrg\Properties;
49
50
use NilPortugues\SchemaOrg\SchemaProperty;
51
52
/**
53
 * {$property['doc']}
54
 */
55
class {$className}Property extends SchemaProperty
56
{
57
    const SCHEMA_URL = "{$property['url']}";
58
    const PROPERTY_NAME = "{$property['name']}";
59
60
    /**
61
     * A list of schemas allowed to use this property.
62
     *
63
     * @var array
64
     */
65
    protected static \$allowedSchemas = [
66
{$allowed}
67
    ];
68
}
69
PHP;
70
            $this->fileSystem->write(
71
                $this->savePath.DIRECTORY_SEPARATOR.$className.'Property.php',
72
                $phpPropertyCode
73
            );
74
        }
75
    }
76
}
77