Completed
Push — master ( 2c5b30...4f9913 )
by WEBEWEB
02:03
created

AbstractQuoteProvider::getAuthors()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Quote;
13
14
use WBW\Bundle\CoreBundle\Provider\QuoteProviderInterface;
15
16
/**
17
 * Abstract quote provider.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\CoreBundle\Quote
21
 * @abstract
22
 */
23
abstract class AbstractQuoteProvider implements QuoteProviderInterface {
24
25
    /**
26
     * Quotes.
27
     *
28
     * @var QuoteInterface[]
29
     */
30
    protected $quotes;
31
32
    /**
33
     * Constructor.
34
     */
35
    protected function __construct() {
36
        $this->setQuotes([]);
37
    }
38
39
    /**
40
     *{@inheritDoc}
41
     */
42
    public function getAuthors() {
43
44
        $authors = [];
45
46
        foreach ($this->quotes as $current) {
47
            if (true === in_array($current->getAuthor(), $authors)) {
48
                continue;
49
            }
50
            $authors[] = $current->getAuthor();
51
        }
52
53
        asort($authors);
54
55
        return $authors;
56
    }
57
58
    /**
59
     * {@onheritDoc}
60
     */
61
    public function getQuotes() {
62
        return $this->quotes;
63
    }
64
65
    /**
66
     * Set the quotes.
67
     *
68
     * @param QuoteInterface[] $quotes The quotes.
69
     * @return QuoteProviderInterface Returns this quote provider.
70
     */
71
    protected function setQuotes(array $quotes) {
72
        $this->quotes = $quotes;
73
        return $this;
74
    }
75
}
76