Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
12 / 14
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
PostCollection
85.71% covered (warning)
85.71%
12 / 14
75.00% covered (warning)
75.00%
3 / 4
6.10
0.00% covered (danger)
0.00%
0 / 1
 getRevisionClass
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWorkflowId
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getBoardWorkflowId
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
2.06
 getRoot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Flow\Collection;
4
5use Flow\Container;
6use Flow\Exception\InvalidDataException;
7use Flow\Model\TopicListEntry;
8use Flow\Model\UUID;
9
10class PostCollection extends LocalCacheAbstractCollection {
11    /**
12     * @var UUID
13     */
14    protected $rootId;
15
16    public static function getRevisionClass() {
17        return \Flow\Model\PostRevision::class;
18    }
19
20    /**
21     * @return UUID
22     * @throws \Flow\Exception\DataModelException
23     */
24    public function getWorkflowId() {
25        // the root post (topic title) has the same id as the workflow
26        if ( !$this->rootId ) {
27            /** @var \Flow\Repository\TreeRepository $treeRepo */
28            $treeRepo = Container::get( 'repository.tree' );
29            $this->rootId = $treeRepo->findRoot( $this->getId() );
30        }
31
32        return $this->rootId;
33    }
34
35    /**
36     * @return UUID
37     * @throws InvalidDataException
38     */
39    public function getBoardWorkflowId() {
40        $found = self::getStorage( TopicListEntry::class )->find(
41            // uses flow_topic_list:topic index, for topic->board lookups
42            [ 'topic_id' => $this->getWorkflowId() ]
43        );
44        if ( !$found ) {
45            throw new InvalidDataException( 'No TopicListEntry founds for topic id ' .
46                $this->getWorkflowId()->getAlphadecimal(), 'invalid-workflow' );
47        }
48
49        /** @var TopicListEntry $topicListEntry */
50        $topicListEntry = $found[0];
51        return $topicListEntry->getListId();
52    }
53
54    /**
55     * Returns the topic title collection this post is associated with.
56     *
57     * @return PostCollection
58     */
59    public function getRoot() {
60        return static::newFromId( $this->getWorkflowId() );
61    }
62}