ArrayWordsTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addWord() 0 4 1
A getNumberWords() 0 3 1
A getWords() 0 3 1
A hasWords() 0 3 1
A setWords() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2020 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\Library\Core\ThirdParty\OcrLad\Model\Attribute;
13
14
use WBW\Library\Core\ThirdParty\OcrLad\Model\Word;
15
16
/**
17
 * Array words trait.
18
 *
19
 * @author webeweb <https://github.com/webeweb>
20
 * @package WBW\Library\Core\ThirdParty\OcrLad\Model\Attribute
21
 */
22
trait ArrayWordsTrait {
23
24
    /**
25
     * Words.
26
     *
27
     * @var Word[]
28
     */
29
    private $words;
30
31
    /**
32
     * Add a word.
33
     *
34
     * @param Word $word The word.
35
     * @return self Returns this instance.
36
     */
37
    public function addWord(Word $word): self {
38
        $this->words[] = $word;
39
        return $this;
40
    }
41
42
    /**
43
     * Get the number of words.
44
     *
45
     * @return int Returns the number of words.
46
     */
47
    public function getNumberWords(): int {
48
        return count($this->words);
49
    }
50
51
    /**
52
     * Get the words.
53
     *
54
     * @return Word[] Returns the words.
55
     */
56
    public function getWords(): array {
57
        return $this->words;
58
    }
59
60
    /**
61
     * Determines if this instance has words.
62
     *
63
     * @return bool Returns true in case of success, false otherwise.
64
     */
65
    public function hasWords(): bool {
66
        return 1 <= $this->getNumberWords();
67
    }
68
69
    /**
70
     * Set the words.
71
     *
72
     * @param Word[] $words The words.
73
     * @return self Returns this instance.
74
     */
75
    protected function setWords(array $words): self {
76
        $this->words = $words;
77
        return $this;
78
    }
79
}