Completed
Branch master (6c7c3c)
by Joschi
02:33
created

MicroformatsFeedTrait::getAuthorApplicationItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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 © 2017 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 © 2017 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 applocation item
57
     *
58
     * @return ApplicationItem h-feed application item
59
     */
60
    protected function getApplicationFeedItem()
61
    {
62
        $authorItem = $this->getAuthorApplicationItem();
63
        $entryItem = $this->getEntryApplicationItem($authorItem);
64
        $feedItem = new ApplicationItem(
65
            Microformats::FORMAT,
66
            new PropertyListFactory(),
67
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'],
68
            [
69
                $this->getPropertyObject('name', new StringValue('John Doe\'s Blog')),
70
                $this->getPropertyObject('author', $authorItem),
71
                $this->getPropertyObject('custom-property', new StringValue('Property for alias testing')),
72
            ],
73
            [$entryItem, $entryItem],
74
            'feed-id',
75
            'feed-language',
76
            'feed-value'
77
        );
78
79
        return $feedItem;
80
    }
81
82
    /**
83
     * Return a property object
84
     *
85
     * @param string $name Name
86
     * @param ValueInterface $value Value
87
     * @return object Property object
88
     */
89
    protected function getPropertyObject($name, ValueInterface $value)
90
    {
91
        return (object)[
92
            'profile' => MicroformatsFactory::MF2_PROFILE_URI,
93
            'name' => $name,
94
            'values' => [$value]
95
        ];
96
    }
97
98
    /**
99
     * Return an author application item
100
     *
101
     * @return ApplicationItem Author application item
102
     */
103
    protected function getAuthorApplicationItem()
104
    {
105
        return new ApplicationItem(
106
            Microformats::FORMAT,
107
            new PropertyListFactory(),
108
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'],
109
            [
110
                $this->getPropertyObject('name', new StringValue('John Doe')),
111
                $this->getPropertyObject('email', new StringValue('[email protected]')),
112
            ]
113
        );
114
    }
115
116
    /**
117
     * Return an entry application item
118
     *
119
     * @param ApplicationItem $authorItem Author application item
120
     * @return ApplicationItem Entry application item
121
     */
122
    protected function getEntryApplicationItem(ApplicationItem $authorItem)
123
    {
124
        return new ApplicationItem(
125
            Microformats::FORMAT,
126
            new PropertyListFactory(),
127
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'],
128
            [
129
                $this->getPropertyObject('name', new StringValue('Famous blog post')),
130
                $this->getPropertyObject('author', $authorItem),
131
            ]
132
        );
133
    }
134
135
    /**
136
     * Create and return an h-feed Microformats item
137
     *
138
     * @return Item h-feed item
139
     */
140
    protected function getFeedItem()
141
    {
142
        return new Item($this->getApplicationFeedItem());
143
    }
144
}
145