Completed
Push — master ( 6db18d...e8104d )
by Nate
02:21
created

AbstractMap::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Collection;
8
9
/**
10
 * Class AbstractMap
11
 *
12
 * A skeletal implementation of [@see MapInterface]
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
abstract class AbstractMap implements MapInterface
17
{
18
    /**
19
     * Adds all the mappings from specified map to this map
20
     *
21
     * @param MapInterface $map
22
     * @return void
23
     */
24 1
    public function putAll(MapInterface $map)
25
    {
26
        /** @var MapEntry $entrySet */
27 1
        foreach ($map->entrySet() as $entrySet) {
28 1
            $this->put($entrySet->key, $entrySet->value);
29
        }
30 1
    }
31
32
    /**
33
     * Find the first [@see MapEntry] in map
34
     *
35
     * The closure will get passed a MapEntry.  Returning true will end the
36
     * loop and return that MapEntry
37
     *
38
     * @param callable $find
39
     * @return MapEntry|null
40
     */
41 2 View Code Duplication
    public function find(callable $find)
1 ignored issue
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...
42
    {
43
        /** @var MapEntry $mapEntry */
44 2
        foreach ($this->entrySet() as $mapEntry) {
45 2
            if (true === $find($mapEntry)) {
46 2
                return $mapEntry;
47
            }
48
        }
49
50 1
        return null;
51
    }
52
53
    /**
54
     * Use a closure to determine existence in the map
55
     *
56
     * The closure will get passed a [@see MapEntry].  Returning true from the
57
     * closure will return true from this method.
58
     *
59
     * @param callable $exists
60
     * @return bool
61
     */
62 1 View Code Duplication
    public function exists(callable $exists): bool
1 ignored issue
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...
63
    {
64
        /** @var MapEntry $mapEntry */
65 1
        foreach ($this->entrySet() as $mapEntry) {
66 1
            if (true === $exists($mapEntry)) {
67 1
                return true;
68
            }
69
        }
70
71 1
        return false;
72
    }
73
}
74