Completed
Push — v5-dev ( a42eb3 )
by Oscar
01:56
created

Comments::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Gettext;
5
6
use JsonSerializable;
7
use IteratorAggregate;
8
use ArrayIterator;
9
use Countable;
10
11
/**
12
 * Class to manage the comments of a translation.
13
 */
14 View Code Duplication
class Comments implements JsonSerializable, Countable, IteratorAggregate
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    protected $comments = [];
17
18
    public function add(string $comment): self
19
    {
20
        if (!in_array($comment, $this->comments)) {
21
            $this->comments[] = $comment;
22
        }
23
24
        return $this;
25
    }
26
27
    public function jsonSerialize()
28
    {
29
        return $this->toArray();
30
    }
31
32
    public function getIterator()
33
    {
34
        return new ArrayIterator($this->comments);
35
    }
36
37
    public function count(): int
38
    {
39
        return count($this->comments);
40
    }
41
42
    public function toArray(): array
43
    {
44
        return $this->comments;
45
    }
46
}
47