MicroformatsFeedTrait::getApplicationFeedItem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 9.584
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category   Jkphl
7
 * @package    Jkphl\Micrometa
8
 * @subpackage Jkphl\Micrometa\Tests
9
 * @author     Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\Micrometa\Tests;
38
39
use Jkphl\Micrometa\Application\Factory\PropertyListFactory;
40
use Jkphl\Micrometa\Application\Item\Item as ApplicationItem;
41
use Jkphl\Micrometa\Application\Value\StringValue;
42
use Jkphl\Micrometa\Domain\Value\ValueInterface;
43
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory;
44
use Jkphl\Micrometa\Infrastructure\Parser\Microformats;
45
use Jkphl\Micrometa\Ports\Item\Item;
46
47
/**
48
 * Trait MicroformatsFeedTrait
49
 *
50
 * @package    Jkphl\Micrometa
51
 * @subpackage Jkphl\Micrometa\Tests
52
 */
53
trait MicroformatsFeedTrait
54
{
55
    /**
56
     * Create and return an h-feed Microformats item
57
     *
58
     * @return Item h-feed item
59
     */
60
    protected function getFeedItem()
61
    {
62
        return new Item($this->getApplicationFeedItem());
63
    }
64
65
    /**
66
     * Create and return an h-feed Microformats applocation item
67
     *
68
     * @return ApplicationItem h-feed application item
69
     */
70
    protected function getApplicationFeedItem()
71
    {
72
        $authorItem = $this->getAuthorApplicationItem();
73
        $entryItem  = $this->getEntryApplicationItem($authorItem);
74
        $feedItem   = new ApplicationItem(
75
            Microformats::FORMAT,
76
            new PropertyListFactory(),
77
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'],
78
            [
79
                $this->getPropertyObject('name', new StringValue('John Doe\'s Blog')),
80
                $this->getPropertyObject('author', $authorItem),
81
                $this->getPropertyObject('custom-property', new StringValue('Property for alias testing')),
82
            ],
83
            [$entryItem, $entryItem],
84
            'feed-id',
85
            'feed-language',
86
            'feed-value'
87
        );
88
89
        return $feedItem;
90
    }
91
92
    /**
93
     * Return an author application item
94
     *
95
     * @return ApplicationItem Author application item
96
     */
97
    protected function getAuthorApplicationItem()
98
    {
99
        return new ApplicationItem(
100
            Microformats::FORMAT,
101
            new PropertyListFactory(),
102
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'],
103
            [
104
                $this->getPropertyObject('name', new StringValue('John Doe')),
105
                $this->getPropertyObject('email', new StringValue('[email protected]')),
106
            ]
107
        );
108
    }
109
110
    /**
111
     * Return a property object
112
     *
113
     * @param string $name          Name
114
     * @param ValueInterface $value Value
115
     *
116
     * @return object Property object
117
     */
118
    protected function getPropertyObject($name, ValueInterface $value)
119
    {
120
        return (object)[
121
            'profile' => MicroformatsFactory::MF2_PROFILE_URI,
122
            'name'    => $name,
123
            'values'  => [$value]
124
        ];
125
    }
126
127
    /**
128
     * Return an entry application item
129
     *
130
     * @param ApplicationItem $authorItem Author application item
131
     *
132
     * @return ApplicationItem Entry application item
133
     */
134
    protected function getEntryApplicationItem(ApplicationItem $authorItem)
135
    {
136
        return new ApplicationItem(
137
            Microformats::FORMAT,
138
            new PropertyListFactory(),
139
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'],
140
            [
141
                $this->getPropertyObject('name', new StringValue('Famous blog post')),
142
                $this->getPropertyObject('author', $authorItem),
143
            ]
144
        );
145
    }
146
}
147