Completed
Push — master ( 4d90dd...0c32ab )
by Sebastian
03:54
created

DefinitionParser   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 18 1
1
<?php
2
3
namespace Spatie\SchemaOrg\Generator\Parser;
4
5
use Spatie\SchemaOrg\Generator\Property;
6
use Symfony\Component\DomCrawler\Crawler;
7
use Spatie\SchemaOrg\Generator\Definitions;
8
use Spatie\SchemaOrg\Generator\TypeCollection;
9
use Spatie\SchemaOrg\Generator\Parser\Tasks\ParseType;
10
use Spatie\SchemaOrg\Generator\Parser\Tasks\ParseProperty;
11
12
class DefinitionParser
13
{
14
    public function parse(Definitions $definitions): TypeCollection
15
    {
16
        $types = $definitions
17
            ->query('[typeof="rdfs:Class"]')
18
            ->each(function (Crawler $crawler) {
19
                return call_user_func(ParseType::fromCrawler($crawler));
20
            });
21
22
        $properties = $definitions
23
            ->query('[typeof="rdf:Property"]')
24
            ->each(function (Crawler $crawler) {
25
                return call_user_func(ParseProperty::fromCrawler($crawler));
26
            });
27
28
        return new TypeCollection(
29
            array_filter($types), array_filter($properties)
30
        );
31
    }
32
}
33