PersistentArrayHashMap::sorted()   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\ArrayHashMapInterface;
13
use Cubiche\Core\Collections\ArrayCollection\ArrayList;
14
use Cubiche\Core\Collections\ArrayCollection\ArraySet;
15
use Cubiche\Core\Collections\DataSource\IteratorDataSource;
16
use Cubiche\Core\Collections\DataSourceHashMap;
17
use Cubiche\Core\Comparable\Comparator;
18
use Cubiche\Core\Comparable\ComparatorInterface;
19
use Cubiche\Core\Specification\SpecificationInterface;
20
21
/**
22
 * PersistentArrayHashMap Class.
23
 *
24
 * @author Karel Osorio Ramírez <[email protected]>
25
 * @author Ivannis Suárez Jerez <[email protected]>
26
 */
27
class PersistentArrayHashMap extends PersistentCollectionAdapter implements ArrayHashMapInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function containsValue($value)
33
    {
34
        return $this->contains($value);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function keys()
41
    {
42
        return new ArraySet($this->getKeys());
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function values()
49
    {
50
        return new ArrayList($this->getValues());
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 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...
57
    {
58
        $elements = $this->collection->toArray();
59
        if ($criteria === null) {
60
            $criteria = new Comparator();
61
        }
62
63
        uksort($elements, function ($a, $b) use ($criteria) {
64
            return $criteria->compare($a, $b);
65
        });
66
67
        $this->clear();
68
        foreach ($elements as $element) {
69
            $this->add($element);
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function sorted(ComparatorInterface $criteria)
77
    {
78
        return new DataSourceHashMap(new IteratorDataSource($this->getIterator(), null, $criteria));
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function find(SpecificationInterface $criteria)
85
    {
86
        return new DataSourceHashMap(new IteratorDataSource($this->getIterator(), $criteria));
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function removeAt($key)
93
    {
94
        $this->remove($key);
95
    }
96
}
97