Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
18 / 30
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReferenceFactory
60.00% covered (warning)
60.00%
18 / 30
33.33% covered (danger)
33.33%
1 / 3
6.60
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 createUrlReference
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 createWikiReference
86.67% covered (warning)
86.67%
13 / 15
0.00% covered (danger)
0.00%
0 / 1
3.02
1<?php
2
3namespace Flow\Parsoid;
4
5use Flow\Conversion\Utils;
6use Flow\Model\URLReference;
7use Flow\Model\UUID;
8use Flow\Model\WikiReference;
9use Flow\Model\Workflow;
10use MediaWiki\Title\Title;
11
12class ReferenceFactory {
13    /**
14     * @var string
15     */
16    protected $wikiId;
17
18    /**
19     * @var UUID
20     */
21    protected $workflowId;
22
23    /**
24     * @var Title
25     */
26    protected $title;
27
28    /**
29     * @var string
30     */
31    protected $objectType;
32
33    /**
34     * @var UUID
35     */
36    protected $objectId;
37
38    /**
39     * @param Workflow $workflow
40     * @param string $objectType
41     * @param UUID $objectId
42     */
43    public function __construct( Workflow $workflow, $objectType, UUID $objectId ) {
44        $this->wikiId = $workflow->getWiki();
45        $this->workflowId = $workflow->getId();
46        $this->title = $workflow->getArticleTitle();
47        $this->objectType = $objectType;
48        $this->objectId = $objectId;
49    }
50
51    /**
52     * @param string $refType
53     * @param string $value
54     * @return URLReference
55     */
56    public function createUrlReference( $refType, $value ) {
57        return new URLReference(
58            UUID::create(),
59            $this->wikiId,
60            $this->workflowId,
61            $this->title,
62            $this->objectType,
63            $this->objectId,
64            $refType,
65            $value
66        );
67    }
68
69    /**
70     * @param string $refType
71     * @param string $value
72     * @return WikiReference|null
73     */
74    public function createWikiReference( $refType, $value ) {
75        $title = Utils::createRelativeTitle( $value, $this->title );
76
77        if ( $title === null ) {
78            return null;
79        }
80
81        // exclude virtual namespaces
82        if ( $title->getNamespace() < 0 ) {
83            return null;
84        }
85
86        return new WikiReference(
87            UUID::create(),
88            $this->wikiId,
89            $this->workflowId,
90            $this->title,
91            $this->objectType,
92            $this->objectId,
93            $refType,
94            $title
95        );
96    }
97}