ParseConstant::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Spatie\SchemaOrg\Generator\Parser\Tasks;
4
5
use Spatie\SchemaOrg\Generator\Constant;
6
use Symfony\Component\DomCrawler\Crawler;
7
8
class ParseConstant extends Task
9
{
10
    public function __invoke(): ?Constant
11
    {
12
        $node = new Crawler($this->definition);
13
14
        $constant = new Constant();
15
16
        $constant->name = preg_replace('/\s+/', '_', $this->getText($node, '[property="rdfs:label"]'));
17
18
        if (empty($constant->name)) {
19
            return null;
20
        }
21
22
        $constant->description = $this->getText($node, '[property="rdfs:comment"]');
23
24
        $constant->value = $this->getAttribute($node, 'resource');
25
26
        return $constant;
27
    }
28
}
29