Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created

MapFeatureAnalysisData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage GeoDispersion
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2021, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\GeoDispersion\Model;
16
17
use Illuminate\Support\Collection;
18
use MyArtJaub\Webtrees\Common\GeoDispersion\GeoAnalysis\GeoAnalysisPlace;
19
20
/**
21
 * Data structure for populating map features with their mapped places and count.
22
 */
23
class MapFeatureAnalysisData
24
{
25
    private string $id;
26
    private int $count;
27
    private bool $in_map;
28
    /**
29
     * @var Collection<GeoAnalysisPlace> $places
30
     */
31
    private Collection $places;
32
33
    /**
34
     * Constructor for MapFeatureAnalysisData
35
     *
36
     * @param string $id
37
     */
38
    public function __construct(string $id)
39
    {
40
        $this->id = $id;
41
        $this->count = 0;
42
        $this->places = new Collection();
43
        $this->in_map = false;
44
    }
45
46
    /**
47
     * Get the list of places mapped to the feature
48
     *
49
     * @return Collection<GeoAnalysisPlace>
50
     */
51
    public function places(): Collection
52
    {
53
        return $this->places;
54
    }
55
56
    /**
57
     * Get the count of analysis items occurring in the feature
58
     *
59
     * @return int
60
     */
61
    public function count(): int
62
    {
63
        return $this->count;
64
    }
65
66
    /**
67
     * Check whether the feature exist in the target map
68
     *
69
     * @return bool
70
     */
71
    public function existsInMap(): bool
72
    {
73
        return $this->in_map;
74
    }
75
76
    /**
77
     * Confirm that the feature exist in the target map
78
     *
79
     * @return self
80
     */
81
    public function tagAsExisting(): self
82
    {
83
        $this->in_map = true;
84
        return $this;
85
    }
86
87
    /**
88
     * Add a GeoAnalysisPlace to the feature
89
     *
90
     * @param GeoAnalysisPlace $place
91
     * @param int $count
92
     * @return self
93
     */
94
    public function add(GeoAnalysisPlace $place, int $count): self
95
    {
96
        if (!$place->isExcluded()) {
97
            $this->places->add($place);
98
            $this->count += $count;
99
        }
100
        return $this;
101
    }
102
}
103