PersistentArrayList::removeAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Infrastructure\Collections\Doctrine\Common\Collections;
11
12
use Cubiche\Core\Collections\ArrayCollection\ArrayListInterface;
13
use Cubiche\Core\Collections\DataSourceList;
14
use Cubiche\Core\Comparable\Comparator;
15
use Cubiche\Core\Comparable\ComparatorInterface;
16
use Cubiche\Core\Specification\SpecificationInterface;
17
use Cubiche\Core\Collections\DataSource\IteratorDataSource;
18
19
/**
20
 * PersistentArrayList Class.
21
 *
22
 * @author Karel Osorio Ramírez <[email protected]>
23
 * @author Ivannis Suárez Jerez <[email protected]>
24
 */
25
class PersistentArrayList extends PersistentCollectionAdapter implements ArrayListInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function addAll($elements)
31
    {
32
        foreach ($elements as $element) {
33
            $this->add($element);
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function find(SpecificationInterface $criteria)
41
    {
42
        return new DataSourceList(new IteratorDataSource($this->getIterator(), $criteria));
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function findOne(SpecificationInterface $criteria)
49
    {
50
        return (new IteratorDataSource($this->getIterator(), $criteria))->findOne();
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function sorted(ComparatorInterface $criteria)
57
    {
58
        return new DataSourceList(new IteratorDataSource($this->getIterator(), null, $criteria));
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 View Code Duplication
    public function sort(ComparatorInterface $criteria = null)
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66
        $elements = $this->collection->toArray();
67
        if ($criteria === null) {
68
            $criteria = new Comparator();
69
        }
70
71
        usort($elements, function ($a, $b) use ($criteria) {
72
            return $criteria->compare($a, $b);
73
        });
74
75
        $this->clear();
76
        foreach ($elements as $element) {
77
            $this->add($element);
78
        }
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function removeAt($key)
85
    {
86
        $this->remove($key);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function removeAll($elements)
93
    {
94
        foreach ($elements as $element) {
95
            $this->removeElement($element);
96
        }
97
    }
98
}
99