Test Failed
Push — master ( 492ea4...9c8472 )
by Bingo
04:47
created

SimpleDirectedGraph   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createBuilder() 0 6 2
A __construct() 0 25 2
1
<?php
2
3
namespace Graphp\Graph\Types;
4
5
use Graphp\Graph\AbstractGraph;
6
use Graphp\Graph\Builder\GraphTypeBuilder;
7
use Graphp\Graph\Builder\GraphBuilder;
8
use Graphp\Util\SupplierUtil;
9
use Graphp\Util\SupplierInterface;
10
11
/**
12
 * Class SimpleDirectedGraph
13
 *
14
 * @package Graphp\Graph\Types
15
 */
16
class SimpleDirectedGraph extends AbstractGraph
17
{
18
    /**
19
     * Create a new simple directed graph
20
     *
21
     * @param string $edgeClass - the edge class
22
     * @param SupplierInterface $vertexSupplier - the vertex supplier
23
     * @param SupplierInterface $edgeSupplier - the edge supplier
24
     * @param bool $weighted - if the graph is weighted
25
     */
26 6
    public function __construct(
27
        ?string $edgeClass = null,
28
        ?SupplierInterface $vertexSupplier = null,
29
        ?SupplierInterface $edgeSupplier = null,
30
        ?bool $weighted = null
31
    ) {
32 6
        $builder = new GraphTypeBuilder();
33 6
        $graphType = $builder->directed()
34 6
                    ->allowSelfLoops(false)
35 6
                    ->allowMultipleEdges(false)
36 6
                    ->weighted($weighted)
37 6
                    ->build();
38 6
        if (!is_null($edgeClass)) {
39 6
            $util = new SupplierUtil();
40 6
            $edgeSupplier = $util->createSupplier($edgeClass);
41 6
            parent::__construct(
42 6
                $vertexSupplier,
43 6
                $edgeSupplier,
44 6
                $graphType
45
            );
46
        } else {
47
            parent::__construct(
48
                $vertexSupplier,
49
                $edgeSupplier,
50
                $graphType
51
            );
52
        }
53 6
    }
54
55
    /**
56
     * Create a simple directed graph builder
57
     *
58
     * @param string $edgeClass - the edge class
59
     * @param SupplierInterface $edgeSupplier - the edge supplier
60
     *
61
     * @return GraphBuilder
62
     */
63
    public function createBuilder(?string $edgeClass = null, ?SupplierInterface $edgeSupplier = null): GraphBuilder
64
    {
65
        if (!is_null($edgeClass)) {
66
            return new GraphBuilder(new SimpleDirectedGraph($edgeClass));
67
        }
68
        return new GraphBuilder(new SimpleDirectedGraph(null, $edgeSupplier));
69
    }
70
}
71