@@ -30,126 +30,126 @@ |
||
30 | 30 | class SourceStatusService |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
35 | - * Arbitrally set to approximately a year around the event date. |
|
36 | - * |
|
37 | - * @var int DATE_PRECISION_MARGIN |
|
38 | - */ |
|
39 | - private const DATE_PRECISION_MARGIN = 180; |
|
40 | - |
|
41 | - /** |
|
42 | - * Return the status of source citations for a fact. |
|
43 | - * |
|
44 | - * @param Fact $fact |
|
45 | - * @return FactSourceStatus |
|
46 | - */ |
|
47 | - public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
48 | - { |
|
49 | - $source_status = new FactSourceStatus(); |
|
50 | - |
|
51 | - $date = $fact->date(); |
|
52 | - $source_status |
|
53 | - ->setFactHasDate($date->isOK()) |
|
54 | - ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
55 | - |
|
56 | - foreach ($fact->getCitations() as $citation) { |
|
57 | - $source_status |
|
58 | - ->setHasSource(true) |
|
59 | - ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
60 | - |
|
61 | - preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
62 | - foreach ($date_matches as $date_match) { |
|
63 | - $source_date = new Date($date_match[1]); |
|
64 | - $source_status |
|
65 | - ->addSourceHasDate($source_date->isOK()) |
|
66 | - ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
67 | - && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
68 | - } |
|
69 | - |
|
70 | - if ($source_status->isFullySourced()) { |
|
71 | - return $source_status; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - return $source_status; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Return the status of sources for a Gedcom record. |
|
80 | - * |
|
81 | - * @param GedcomRecord $record |
|
82 | - * @return SourceStatus |
|
83 | - */ |
|
84 | - public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
85 | - { |
|
86 | - $source_status = new SourceStatus(); |
|
87 | - |
|
88 | - foreach ($record->facts(['SOUR']) as $source) { |
|
89 | - $source_status |
|
90 | - ->setHasSource(true) |
|
91 | - ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
92 | - |
|
93 | - if ($source_status->isFullySourced()) { |
|
94 | - return $source_status; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - return $source_status; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Return the status of source citations for a list of fact types associated with a record. |
|
103 | - * |
|
104 | - * @param GedcomRecord $record |
|
105 | - * @param string[] $tags |
|
106 | - * @return FactSourceStatus |
|
107 | - */ |
|
108 | - public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
109 | - { |
|
110 | - $source_status = new NullFactSourceStatus(); |
|
111 | - |
|
112 | - foreach ($record->facts($tags) as $fact) { |
|
113 | - $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
114 | - if ($source_status->isFullySourced()) { |
|
115 | - return $source_status; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $source_status; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Return the status of source citations for an individual's birth events. |
|
124 | - * |
|
125 | - * @param Individual $individual |
|
126 | - * @return FactSourceStatus |
|
127 | - */ |
|
128 | - public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
129 | - { |
|
130 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Return the status of source citations for an individual's death events. |
|
135 | - * |
|
136 | - * @param Individual $individual |
|
137 | - * @return FactSourceStatus |
|
138 | - */ |
|
139 | - public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
140 | - { |
|
141 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Return the status of source citations for a family's marriage events. |
|
146 | - * |
|
147 | - * @param Family $family |
|
148 | - * @return FactSourceStatus |
|
149 | - */ |
|
150 | - public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
151 | - { |
|
152 | - $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']); |
|
153 | - return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
154 | - } |
|
33 | + /** |
|
34 | + * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
35 | + * Arbitrally set to approximately a year around the event date. |
|
36 | + * |
|
37 | + * @var int DATE_PRECISION_MARGIN |
|
38 | + */ |
|
39 | + private const DATE_PRECISION_MARGIN = 180; |
|
40 | + |
|
41 | + /** |
|
42 | + * Return the status of source citations for a fact. |
|
43 | + * |
|
44 | + * @param Fact $fact |
|
45 | + * @return FactSourceStatus |
|
46 | + */ |
|
47 | + public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
48 | + { |
|
49 | + $source_status = new FactSourceStatus(); |
|
50 | + |
|
51 | + $date = $fact->date(); |
|
52 | + $source_status |
|
53 | + ->setFactHasDate($date->isOK()) |
|
54 | + ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
55 | + |
|
56 | + foreach ($fact->getCitations() as $citation) { |
|
57 | + $source_status |
|
58 | + ->setHasSource(true) |
|
59 | + ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
60 | + |
|
61 | + preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
62 | + foreach ($date_matches as $date_match) { |
|
63 | + $source_date = new Date($date_match[1]); |
|
64 | + $source_status |
|
65 | + ->addSourceHasDate($source_date->isOK()) |
|
66 | + ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
67 | + && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
68 | + } |
|
69 | + |
|
70 | + if ($source_status->isFullySourced()) { |
|
71 | + return $source_status; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + return $source_status; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Return the status of sources for a Gedcom record. |
|
80 | + * |
|
81 | + * @param GedcomRecord $record |
|
82 | + * @return SourceStatus |
|
83 | + */ |
|
84 | + public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
85 | + { |
|
86 | + $source_status = new SourceStatus(); |
|
87 | + |
|
88 | + foreach ($record->facts(['SOUR']) as $source) { |
|
89 | + $source_status |
|
90 | + ->setHasSource(true) |
|
91 | + ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
92 | + |
|
93 | + if ($source_status->isFullySourced()) { |
|
94 | + return $source_status; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + return $source_status; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Return the status of source citations for a list of fact types associated with a record. |
|
103 | + * |
|
104 | + * @param GedcomRecord $record |
|
105 | + * @param string[] $tags |
|
106 | + * @return FactSourceStatus |
|
107 | + */ |
|
108 | + public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
109 | + { |
|
110 | + $source_status = new NullFactSourceStatus(); |
|
111 | + |
|
112 | + foreach ($record->facts($tags) as $fact) { |
|
113 | + $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
114 | + if ($source_status->isFullySourced()) { |
|
115 | + return $source_status; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $source_status; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Return the status of source citations for an individual's birth events. |
|
124 | + * |
|
125 | + * @param Individual $individual |
|
126 | + * @return FactSourceStatus |
|
127 | + */ |
|
128 | + public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
129 | + { |
|
130 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Return the status of source citations for an individual's death events. |
|
135 | + * |
|
136 | + * @param Individual $individual |
|
137 | + * @return FactSourceStatus |
|
138 | + */ |
|
139 | + public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
140 | + { |
|
141 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Return the status of source citations for a family's marriage events. |
|
146 | + * |
|
147 | + * @param Family $family |
|
148 | + * @return FactSourceStatus |
|
149 | + */ |
|
150 | + public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
151 | + { |
|
152 | + $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']); |
|
153 | + return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
154 | + } |
|
155 | 155 | } |
@@ -25,41 +25,41 @@ |
||
25 | 25 | */ |
26 | 26 | class GeoAnalysisService |
27 | 27 | { |
28 | - private ModuleService $module_service; |
|
28 | + private ModuleService $module_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for MapDefinitionsService |
|
32 | - * |
|
33 | - * @param ModuleService $module_service |
|
34 | - */ |
|
35 | - public function __construct(ModuleService $module_service) |
|
36 | - { |
|
37 | - $this->module_service = $module_service; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for MapDefinitionsService |
|
32 | + * |
|
33 | + * @param ModuleService $module_service |
|
34 | + */ |
|
35 | + public function __construct(ModuleService $module_service) |
|
36 | + { |
|
37 | + $this->module_service = $module_service; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get all available geographical dispersion analyses. |
|
42 | - * |
|
43 | - * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
44 | - * |
|
45 | - * @param bool $include_disabled |
|
46 | - * @return Collection<GeoAnalysisInterface> |
|
47 | - */ |
|
48 | - public function all(bool $include_disabled = false): Collection |
|
49 | - { |
|
50 | - /** @var Collection<GeoAnalysisInterface> $geoanalyses */ |
|
51 | - $geoanalyses = $this->module_service |
|
52 | - ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
53 | - ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
54 | - ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
55 | - try { |
|
56 | - $analysis = app($analysis_class); |
|
57 | - return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
58 | - } catch (BindingResolutionException $ex) { |
|
59 | - return null; |
|
60 | - } |
|
61 | - })->filter(); |
|
40 | + /** |
|
41 | + * Get all available geographical dispersion analyses. |
|
42 | + * |
|
43 | + * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
44 | + * |
|
45 | + * @param bool $include_disabled |
|
46 | + * @return Collection<GeoAnalysisInterface> |
|
47 | + */ |
|
48 | + public function all(bool $include_disabled = false): Collection |
|
49 | + { |
|
50 | + /** @var Collection<GeoAnalysisInterface> $geoanalyses */ |
|
51 | + $geoanalyses = $this->module_service |
|
52 | + ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
53 | + ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
54 | + ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
55 | + try { |
|
56 | + $analysis = app($analysis_class); |
|
57 | + return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
58 | + } catch (BindingResolutionException $ex) { |
|
59 | + return null; |
|
60 | + } |
|
61 | + })->filter(); |
|
62 | 62 | |
63 | - return $geoanalyses; |
|
64 | - } |
|
63 | + return $geoanalyses; |
|
64 | + } |
|
65 | 65 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $geoanalyses = $this->module_service |
52 | 52 | ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
53 | 53 | ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
54 | - ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
54 | + ->map(static function(string $analysis_class): ?GeoAnalysisInterface { |
|
55 | 55 | try { |
56 | 56 | $analysis = app($analysis_class); |
57 | 57 | return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
@@ -25,41 +25,41 @@ |
||
25 | 25 | */ |
26 | 26 | class PlaceMapperService |
27 | 27 | { |
28 | - private ModuleService $module_service; |
|
28 | + private ModuleService $module_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for PlaceMapperService |
|
32 | - * |
|
33 | - * @param ModuleService $module_service |
|
34 | - */ |
|
35 | - public function __construct(ModuleService $module_service) |
|
36 | - { |
|
37 | - $this->module_service = $module_service; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for PlaceMapperService |
|
32 | + * |
|
33 | + * @param ModuleService $module_service |
|
34 | + */ |
|
35 | + public function __construct(ModuleService $module_service) |
|
36 | + { |
|
37 | + $this->module_service = $module_service; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get all place mappers available. |
|
42 | - * |
|
43 | - * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
44 | - * |
|
45 | - * @param bool $include_disabled |
|
46 | - * @return Collection<PlaceMapperInterface> |
|
47 | - */ |
|
48 | - public function all(bool $include_disabled = false): Collection |
|
49 | - { |
|
50 | - /** @var Collection<PlaceMapperInterface> $place_mappers */ |
|
51 | - $place_mappers = $this->module_service |
|
52 | - ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
53 | - ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
54 | - ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
55 | - try { |
|
56 | - $mapper = app($mapper_class); |
|
57 | - return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
58 | - } catch (BindingResolutionException $ex) { |
|
59 | - return null; |
|
60 | - } |
|
61 | - })->filter(); |
|
40 | + /** |
|
41 | + * Get all place mappers available. |
|
42 | + * |
|
43 | + * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
44 | + * |
|
45 | + * @param bool $include_disabled |
|
46 | + * @return Collection<PlaceMapperInterface> |
|
47 | + */ |
|
48 | + public function all(bool $include_disabled = false): Collection |
|
49 | + { |
|
50 | + /** @var Collection<PlaceMapperInterface> $place_mappers */ |
|
51 | + $place_mappers = $this->module_service |
|
52 | + ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
53 | + ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
54 | + ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
55 | + try { |
|
56 | + $mapper = app($mapper_class); |
|
57 | + return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
58 | + } catch (BindingResolutionException $ex) { |
|
59 | + return null; |
|
60 | + } |
|
61 | + })->filter(); |
|
62 | 62 | |
63 | - return $place_mappers; |
|
64 | - } |
|
63 | + return $place_mappers; |
|
64 | + } |
|
65 | 65 | } |
@@ -48,10 +48,10 @@ |
||
48 | 48 | public function all(bool $include_disabled = false): Collection |
49 | 49 | { |
50 | 50 | /** @var Collection<PlaceMapperInterface> $place_mappers */ |
51 | - $place_mappers = $this->module_service |
|
51 | + $place_mappers = $this->module_service |
|
52 | 52 | ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
53 | 53 | ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
54 | - ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
54 | + ->map(static function(string $mapper_class): ?PlaceMapperInterface { |
|
55 | 55 | try { |
56 | 56 | $mapper = app($mapper_class); |
57 | 57 | return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
@@ -24,67 +24,67 @@ |
||
24 | 24 | */ |
25 | 25 | trait PlaceMapperTrait |
26 | 26 | { |
27 | - private ?PlaceMapperConfigInterface $config = null; |
|
27 | + private ?PlaceMapperConfigInterface $config = null; |
|
28 | 28 | |
29 | - /** @var array<string, mixed> $data */ |
|
30 | - private array $data = []; |
|
29 | + /** @var array<string, mixed> $data */ |
|
30 | + private array $data = []; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Implementation of PlaceMapperInterface::boot |
|
34 | - * |
|
35 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
36 | - */ |
|
37 | - public function boot(): void |
|
38 | - { |
|
39 | - } |
|
32 | + /** |
|
33 | + * Implementation of PlaceMapperInterface::boot |
|
34 | + * |
|
35 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
36 | + */ |
|
37 | + public function boot(): void |
|
38 | + { |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Implementation of PlaceMapperInterface::config |
|
43 | - * |
|
44 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
45 | - * |
|
46 | - * @return PlaceMapperConfigInterface |
|
47 | - */ |
|
48 | - public function config(): PlaceMapperConfigInterface |
|
49 | - { |
|
50 | - return $this->config ?? new NullPlaceMapperConfig(); |
|
51 | - } |
|
41 | + /** |
|
42 | + * Implementation of PlaceMapperInterface::config |
|
43 | + * |
|
44 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
45 | + * |
|
46 | + * @return PlaceMapperConfigInterface |
|
47 | + */ |
|
48 | + public function config(): PlaceMapperConfigInterface |
|
49 | + { |
|
50 | + return $this->config ?? new NullPlaceMapperConfig(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Implementation of PlaceMapperInterface::setConfig |
|
55 | - * |
|
56 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig() |
|
57 | - * |
|
58 | - * @param PlaceMapperConfigInterface $config |
|
59 | - */ |
|
60 | - public function setConfig(PlaceMapperConfigInterface $config): void |
|
61 | - { |
|
62 | - $this->config = $config; |
|
63 | - } |
|
53 | + /** |
|
54 | + * Implementation of PlaceMapperInterface::setConfig |
|
55 | + * |
|
56 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig() |
|
57 | + * |
|
58 | + * @param PlaceMapperConfigInterface $config |
|
59 | + */ |
|
60 | + public function setConfig(PlaceMapperConfigInterface $config): void |
|
61 | + { |
|
62 | + $this->config = $config; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Implementation of PlaceMapperInterface::data |
|
67 | - * |
|
68 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data() |
|
69 | - * |
|
70 | - * @param string $key |
|
71 | - * @return NULL|mixed |
|
72 | - */ |
|
73 | - public function data(string $key) |
|
74 | - { |
|
75 | - return $this->data[$key] ?? null; |
|
76 | - } |
|
65 | + /** |
|
66 | + * Implementation of PlaceMapperInterface::data |
|
67 | + * |
|
68 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data() |
|
69 | + * |
|
70 | + * @param string $key |
|
71 | + * @return NULL|mixed |
|
72 | + */ |
|
73 | + public function data(string $key) |
|
74 | + { |
|
75 | + return $this->data[$key] ?? null; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Implementation of PlaceMapperInterface::setData |
|
80 | - * |
|
81 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData() |
|
82 | - * |
|
83 | - * @param string $key |
|
84 | - * @param mixed|null $data |
|
85 | - */ |
|
86 | - public function setData(string $key, $data): void |
|
87 | - { |
|
88 | - $this->data[$key] = $data; |
|
89 | - } |
|
78 | + /** |
|
79 | + * Implementation of PlaceMapperInterface::setData |
|
80 | + * |
|
81 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData() |
|
82 | + * |
|
83 | + * @param string $key |
|
84 | + * @param mixed|null $data |
|
85 | + */ |
|
86 | + public function setData(string $key, $data): void |
|
87 | + { |
|
88 | + $this->data[$key] = $data; |
|
89 | + } |
|
90 | 90 | } |
@@ -21,65 +21,65 @@ |
||
21 | 21 | */ |
22 | 22 | trait TopFilteredPlaceMapperTrait |
23 | 23 | { |
24 | - /** |
|
25 | - * @var Place[] $top_places |
|
26 | - */ |
|
27 | - private array $top_places = []; |
|
24 | + /** |
|
25 | + * @var Place[] $top_places |
|
26 | + */ |
|
27 | + private array $top_places = []; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Get the list of top level places. |
|
31 | - * |
|
32 | - * @return Place[] |
|
33 | - */ |
|
34 | - public function topPlaces(): array |
|
35 | - { |
|
36 | - return $this->top_places; |
|
37 | - } |
|
29 | + /** |
|
30 | + * Get the list of top level places. |
|
31 | + * |
|
32 | + * @return Place[] |
|
33 | + */ |
|
34 | + public function topPlaces(): array |
|
35 | + { |
|
36 | + return $this->top_places; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Set the list of defined top level places. |
|
41 | - * |
|
42 | - * @param Place[] $top_places |
|
43 | - */ |
|
44 | - public function setTopPlaces(array $top_places): void |
|
45 | - { |
|
46 | - $this->top_places = collect($top_places) |
|
47 | - ->filter( |
|
48 | - /** @psalm-suppress MissingClosureParamType */ |
|
49 | - fn($top_places): bool => $top_places instanceof Place |
|
50 | - )->toArray(); |
|
51 | - } |
|
39 | + /** |
|
40 | + * Set the list of defined top level places. |
|
41 | + * |
|
42 | + * @param Place[] $top_places |
|
43 | + */ |
|
44 | + public function setTopPlaces(array $top_places): void |
|
45 | + { |
|
46 | + $this->top_places = collect($top_places) |
|
47 | + ->filter( |
|
48 | + /** @psalm-suppress MissingClosureParamType */ |
|
49 | + fn($top_places): bool => $top_places instanceof Place |
|
50 | + )->toArray(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Check whether a string ($haystack) ends with another string ($needle) |
|
55 | - * |
|
56 | - * {@internal This is redundant with the function str_ends_with in PHP8} |
|
57 | - * |
|
58 | - * @param string $haystack |
|
59 | - * @param string $needle |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - private function endsWith(string $haystack, string $needle): bool |
|
63 | - { |
|
64 | - return substr_compare($haystack, $needle, -strlen($needle)) === 0; |
|
65 | - } |
|
53 | + /** |
|
54 | + * Check whether a string ($haystack) ends with another string ($needle) |
|
55 | + * |
|
56 | + * {@internal This is redundant with the function str_ends_with in PHP8} |
|
57 | + * |
|
58 | + * @param string $haystack |
|
59 | + * @param string $needle |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + private function endsWith(string $haystack, string $needle): bool |
|
63 | + { |
|
64 | + return substr_compare($haystack, $needle, -strlen($needle)) === 0; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Check whether a Place belongs to one of the defined top places. |
|
69 | - * |
|
70 | - * @param Place $place |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - protected function belongsToTopLevels(Place $place): bool |
|
74 | - { |
|
75 | - foreach ($this->top_places as $top_place) { |
|
76 | - if ( |
|
77 | - $top_place->tree()->id() === $place->tree()->id() && |
|
78 | - $this->endsWith($place->gedcomName(), $top_place->gedcomName()) |
|
79 | - ) { |
|
80 | - return true; |
|
81 | - } |
|
82 | - } |
|
83 | - return false; |
|
84 | - } |
|
67 | + /** |
|
68 | + * Check whether a Place belongs to one of the defined top places. |
|
69 | + * |
|
70 | + * @param Place $place |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + protected function belongsToTopLevels(Place $place): bool |
|
74 | + { |
|
75 | + foreach ($this->top_places as $top_place) { |
|
76 | + if ( |
|
77 | + $top_place->tree()->id() === $place->tree()->id() && |
|
78 | + $this->endsWith($place->gedcomName(), $top_place->gedcomName()) |
|
79 | + ) { |
|
80 | + return true; |
|
81 | + } |
|
82 | + } |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
5 | - * |
|
6 | - * @package MyArtJaub\Webtrees |
|
7 | - * @subpackage Hooks |
|
8 | - * @author Jonathan Jaubart <[email protected]> |
|
9 | - * @copyright Copyright (c) 2011-2021, Jonathan Jaubart |
|
10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | - */ |
|
4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
5 | + * |
|
6 | + * @package MyArtJaub\Webtrees |
|
7 | + * @subpackage Hooks |
|
8 | + * @author Jonathan Jaubart <[email protected]> |
|
9 | + * @copyright Copyright (c) 2011-2021, Jonathan Jaubart |
|
10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | declare(strict_types=1); |
14 | 14 | |
@@ -21,31 +21,31 @@ discard block |
||
21 | 21 | */ |
22 | 22 | interface CustomSimpleTagEditorInterface extends HookInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Add the tag in the hierarchy of the expected tags |
|
26 | - * |
|
27 | - * @param array<string, mixed> $expected_tags |
|
28 | - * @return array<string, mixed> |
|
29 | - */ |
|
30 | - public function addExpectedTags(array $expected_tags): array; |
|
24 | + /** |
|
25 | + * Add the tag in the hierarchy of the expected tags |
|
26 | + * |
|
27 | + * @param array<string, mixed> $expected_tags |
|
28 | + * @return array<string, mixed> |
|
29 | + */ |
|
30 | + public function addExpectedTags(array $expected_tags): array; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Try to get a label for a tag |
|
34 | - * |
|
35 | - * @param string $tag |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getLabel(string $tag): string; |
|
32 | + /** |
|
33 | + * Try to get a label for a tag |
|
34 | + * |
|
35 | + * @param string $tag |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getLabel(string $tag): string; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns HTML code for editing the custom tag. |
|
42 | - * |
|
43 | - * @param string $tag |
|
44 | - * @param string $id |
|
45 | - * @param string $name |
|
46 | - * @param string $value |
|
47 | - * @param Tree $tree |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string; |
|
40 | + /** |
|
41 | + * Returns HTML code for editing the custom tag. |
|
42 | + * |
|
43 | + * @param string $tag |
|
44 | + * @param string $id |
|
45 | + * @param string $name |
|
46 | + * @param string $value |
|
47 | + * @param Tree $tree |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string; |
|
51 | 51 | } |
@@ -23,104 +23,104 @@ |
||
23 | 23 | */ |
24 | 24 | class GeoAnalysisResults |
25 | 25 | { |
26 | - private GeoAnalysisResult $global; |
|
26 | + private GeoAnalysisResult $global; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var Collection<string, GeoAnalysisResult> $detailed |
|
30 | - */ |
|
31 | - private Collection $detailed; |
|
28 | + /** |
|
29 | + * @var Collection<string, GeoAnalysisResult> $detailed |
|
30 | + */ |
|
31 | + private Collection $detailed; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for GeoAnalysisResults |
|
35 | - */ |
|
36 | - public function __construct() |
|
37 | - { |
|
38 | - $this->global = new GeoAnalysisResult('Global', 0); |
|
39 | - $this->detailed = new Collection(); |
|
40 | - } |
|
33 | + /** |
|
34 | + * Constructor for GeoAnalysisResults |
|
35 | + */ |
|
36 | + public function __construct() |
|
37 | + { |
|
38 | + $this->global = new GeoAnalysisResult('Global', 0); |
|
39 | + $this->detailed = new Collection(); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Global result of the geographical analysis |
|
44 | - * |
|
45 | - * @return GeoAnalysisResult |
|
46 | - */ |
|
47 | - public function global(): GeoAnalysisResult |
|
48 | - { |
|
49 | - return $this->global; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Global result of the geographical analysis |
|
44 | + * |
|
45 | + * @return GeoAnalysisResult |
|
46 | + */ |
|
47 | + public function global(): GeoAnalysisResult |
|
48 | + { |
|
49 | + return $this->global; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * List of results by category of the geographical analysis |
|
54 | - * |
|
55 | - * @return Collection<string, GeoAnalysisResult> |
|
56 | - */ |
|
57 | - public function detailed(): Collection |
|
58 | - { |
|
59 | - return $this->detailed; |
|
60 | - } |
|
52 | + /** |
|
53 | + * List of results by category of the geographical analysis |
|
54 | + * |
|
55 | + * @return Collection<string, GeoAnalysisResult> |
|
56 | + */ |
|
57 | + public function detailed(): Collection |
|
58 | + { |
|
59 | + return $this->detailed; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * List of results by category of the geographical analysis. |
|
64 | - * The list is sorted first by the category order, then by the category description |
|
65 | - * |
|
66 | - * @return Collection<string, GeoAnalysisResult> |
|
67 | - */ |
|
68 | - public function sortedDetailed(): Collection |
|
69 | - { |
|
70 | - return $this->detailed->sortBy([ |
|
71 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
72 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
73 | - I18N::comparator()($a->description(), $b->description()) |
|
74 | - ]); |
|
75 | - } |
|
62 | + /** |
|
63 | + * List of results by category of the geographical analysis. |
|
64 | + * The list is sorted first by the category order, then by the category description |
|
65 | + * |
|
66 | + * @return Collection<string, GeoAnalysisResult> |
|
67 | + */ |
|
68 | + public function sortedDetailed(): Collection |
|
69 | + { |
|
70 | + return $this->detailed->sortBy([ |
|
71 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
72 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
73 | + I18N::comparator()($a->description(), $b->description()) |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Add a GeoAnalysis Place to the global result |
|
79 | - * |
|
80 | - * @param GeoAnalysisPlace $place |
|
81 | - */ |
|
82 | - public function addPlace(GeoAnalysisPlace $place): void |
|
83 | - { |
|
84 | - $this->global()->addPlace($place); |
|
85 | - } |
|
77 | + /** |
|
78 | + * Add a GeoAnalysis Place to the global result |
|
79 | + * |
|
80 | + * @param GeoAnalysisPlace $place |
|
81 | + */ |
|
82 | + public function addPlace(GeoAnalysisPlace $place): void |
|
83 | + { |
|
84 | + $this->global()->addPlace($place); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Add a new category to the list of results, if it does not exist yet |
|
89 | - * |
|
90 | - * @param string $description |
|
91 | - * @param int $order |
|
92 | - */ |
|
93 | - public function addCategory(string $description, int $order): void |
|
94 | - { |
|
95 | - if (!$this->detailed->has($description)) { |
|
96 | - $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
97 | - } |
|
98 | - } |
|
87 | + /** |
|
88 | + * Add a new category to the list of results, if it does not exist yet |
|
89 | + * |
|
90 | + * @param string $description |
|
91 | + * @param int $order |
|
92 | + */ |
|
93 | + public function addCategory(string $description, int $order): void |
|
94 | + { |
|
95 | + if (!$this->detailed->has($description)) { |
|
96 | + $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Add a GeoAnalysis Place to a category result, if the category exist. |
|
102 | - * |
|
103 | - * @param string $category_name |
|
104 | - * @param GeoAnalysisPlace $place |
|
105 | - */ |
|
106 | - public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
107 | - { |
|
108 | - if ($this->detailed->has($category_name)) { |
|
109 | - $this->detailed->get($category_name)->addPlace($place); |
|
110 | - } |
|
111 | - } |
|
100 | + /** |
|
101 | + * Add a GeoAnalysis Place to a category result, if the category exist. |
|
102 | + * |
|
103 | + * @param string $category_name |
|
104 | + * @param GeoAnalysisPlace $place |
|
105 | + */ |
|
106 | + public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
107 | + { |
|
108 | + if ($this->detailed->has($category_name)) { |
|
109 | + $this->detailed->get($category_name)->addPlace($place); |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
115 | - * |
|
116 | - * @param string $category_name |
|
117 | - * @param GeoAnalysisPlace $place |
|
118 | - */ |
|
119 | - public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
120 | - { |
|
121 | - if (!$this->detailed->has($category_name)) { |
|
122 | - $this->addCategory($category_name, $category_order); |
|
123 | - } |
|
124 | - $this->addPlaceInCreatedCategory($category_name, $place); |
|
125 | - } |
|
113 | + /** |
|
114 | + * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
115 | + * |
|
116 | + * @param string $category_name |
|
117 | + * @param GeoAnalysisPlace $place |
|
118 | + */ |
|
119 | + public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
120 | + { |
|
121 | + if (!$this->detailed->has($category_name)) { |
|
122 | + $this->addCategory($category_name, $category_order); |
|
123 | + } |
|
124 | + $this->addPlaceInCreatedCategory($category_name, $place); |
|
125 | + } |
|
126 | 126 | } |
@@ -25,105 +25,105 @@ |
||
25 | 25 | */ |
26 | 26 | class GenericPlaceMapperConfig implements PlaceMapperConfigInterface |
27 | 27 | { |
28 | - /** @var array<string, mixed> $config */ |
|
29 | - private array $config = []; |
|
28 | + /** @var array<string, mixed> $config */ |
|
29 | + private array $config = []; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Get the generic mapper's config |
|
33 | - * |
|
34 | - * @return array<string, mixed> |
|
35 | - */ |
|
36 | - public function config(): array |
|
37 | - { |
|
38 | - return $this->config; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Get the generic mapper's config |
|
33 | + * |
|
34 | + * @return array<string, mixed> |
|
35 | + */ |
|
36 | + public function config(): array |
|
37 | + { |
|
38 | + return $this->config; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Set the generic mapper's config |
|
43 | - * |
|
44 | - * @param array<string, mixed> $config |
|
45 | - * @return $this |
|
46 | - */ |
|
47 | - public function setConfig(array $config): self |
|
48 | - { |
|
49 | - $this->config = $config; |
|
50 | - return $this; |
|
51 | - } |
|
41 | + /** |
|
42 | + * Set the generic mapper's config |
|
43 | + * |
|
44 | + * @param array<string, mixed> $config |
|
45 | + * @return $this |
|
46 | + */ |
|
47 | + public function setConfig(array $config): self |
|
48 | + { |
|
49 | + $this->config = $config; |
|
50 | + return $this; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inheritDoc} |
|
55 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
56 | - */ |
|
57 | - public function get(string $key, $default = null) |
|
58 | - { |
|
59 | - return $this->config[$key] ?? $default; |
|
60 | - } |
|
53 | + /** |
|
54 | + * {@inheritDoc} |
|
55 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
56 | + */ |
|
57 | + public function get(string $key, $default = null) |
|
58 | + { |
|
59 | + return $this->config[$key] ?? $default; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritDoc} |
|
64 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
65 | - */ |
|
66 | - public function has(string $key): bool |
|
67 | - { |
|
68 | - return key_exists($key, $this->config); |
|
69 | - } |
|
62 | + /** |
|
63 | + * {@inheritDoc} |
|
64 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
65 | + */ |
|
66 | + public function has(string $key): bool |
|
67 | + { |
|
68 | + return key_exists($key, $this->config); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritDoc} |
|
73 | - * @see \JsonSerializable::jsonSerialize() |
|
74 | - */ |
|
75 | - public function jsonSerialize() |
|
76 | - { |
|
77 | - return [ |
|
78 | - 'class' => get_class($this), |
|
79 | - 'config' => $this->jsonSerializeConfig() |
|
80 | - ]; |
|
81 | - } |
|
71 | + /** |
|
72 | + * {@inheritDoc} |
|
73 | + * @see \JsonSerializable::jsonSerialize() |
|
74 | + */ |
|
75 | + public function jsonSerialize() |
|
76 | + { |
|
77 | + return [ |
|
78 | + 'class' => get_class($this), |
|
79 | + 'config' => $this->jsonSerializeConfig() |
|
80 | + ]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Returns a representation of the mapper config compatible with Json serialisation |
|
85 | - * |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function jsonSerializeConfig() |
|
89 | - { |
|
90 | - return $this->config; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Returns a representation of the mapper config compatible with Json serialisation |
|
85 | + * |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function jsonSerializeConfig() |
|
89 | + { |
|
90 | + return $this->config; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * {@inheritDoc} |
|
95 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
96 | - * |
|
97 | - * @param mixed $config |
|
98 | - * @return $this |
|
99 | - */ |
|
100 | - public function jsonDeserialize($config): self |
|
101 | - { |
|
102 | - if (is_string($config)) { |
|
103 | - return $this->jsonDeserialize(json_decode($config)); |
|
104 | - } |
|
105 | - if (is_array($config)) { |
|
106 | - return $this->setConfig($config); |
|
107 | - } |
|
108 | - return $this; |
|
109 | - } |
|
93 | + /** |
|
94 | + * {@inheritDoc} |
|
95 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
96 | + * |
|
97 | + * @param mixed $config |
|
98 | + * @return $this |
|
99 | + */ |
|
100 | + public function jsonDeserialize($config): self |
|
101 | + { |
|
102 | + if (is_string($config)) { |
|
103 | + return $this->jsonDeserialize(json_decode($config)); |
|
104 | + } |
|
105 | + if (is_array($config)) { |
|
106 | + return $this->setConfig($config); |
|
107 | + } |
|
108 | + return $this; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * {@inheritDoc} |
|
113 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
114 | - */ |
|
115 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
116 | - { |
|
117 | - return ''; |
|
118 | - } |
|
111 | + /** |
|
112 | + * {@inheritDoc} |
|
113 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
114 | + */ |
|
115 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
116 | + { |
|
117 | + return ''; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * {@inheritDoc} |
|
122 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
123 | - * @return $this |
|
124 | - */ |
|
125 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
126 | - { |
|
127 | - return $this; |
|
128 | - } |
|
120 | + /** |
|
121 | + * {@inheritDoc} |
|
122 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
123 | + * @return $this |
|
124 | + */ |
|
125 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
126 | + { |
|
127 | + return $this; |
|
128 | + } |
|
129 | 129 | } |
@@ -24,252 +24,252 @@ |
||
24 | 24 | */ |
25 | 25 | class TaskSchedule |
26 | 26 | { |
27 | - private int $id; |
|
28 | - private bool $enabled; |
|
29 | - private string $task_id; |
|
30 | - private Carbon $last_run; |
|
31 | - private bool $last_result; |
|
32 | - private CarbonInterval $frequency; |
|
33 | - private int $nb_occurrences; |
|
34 | - private bool $is_running; |
|
27 | + private int $id; |
|
28 | + private bool $enabled; |
|
29 | + private string $task_id; |
|
30 | + private Carbon $last_run; |
|
31 | + private bool $last_result; |
|
32 | + private CarbonInterval $frequency; |
|
33 | + private int $nb_occurrences; |
|
34 | + private bool $is_running; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for TaskSchedule |
|
38 | - * |
|
39 | - * @param int $id Schedule ID |
|
40 | - * @param string $task_id Task ID |
|
41 | - * @param bool $enabled Is the schedule enabled |
|
42 | - * @param Carbon $last_run Last successful run date/time |
|
43 | - * @param bool $last_result Result of the last run |
|
44 | - * @param CarbonInterval $frequency Schedule frequency |
|
45 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
46 | - * @param bool $is_running Is the task currently running |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - int $id, |
|
50 | - string $task_id, |
|
51 | - bool $enabled, |
|
52 | - Carbon $last_run, |
|
53 | - bool $last_result, |
|
54 | - CarbonInterval $frequency, |
|
55 | - int $nb_occurrences, |
|
56 | - bool $is_running |
|
57 | - ) { |
|
58 | - $this->id = $id; |
|
59 | - $this->task_id = $task_id; |
|
60 | - $this->enabled = $enabled; |
|
61 | - $this->last_run = $last_run; |
|
62 | - $this->last_result = $last_result; |
|
63 | - $this->frequency = $frequency; |
|
64 | - $this->nb_occurrences = $nb_occurrences; |
|
65 | - $this->is_running = $is_running; |
|
66 | - } |
|
36 | + /** |
|
37 | + * Constructor for TaskSchedule |
|
38 | + * |
|
39 | + * @param int $id Schedule ID |
|
40 | + * @param string $task_id Task ID |
|
41 | + * @param bool $enabled Is the schedule enabled |
|
42 | + * @param Carbon $last_run Last successful run date/time |
|
43 | + * @param bool $last_result Result of the last run |
|
44 | + * @param CarbonInterval $frequency Schedule frequency |
|
45 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
46 | + * @param bool $is_running Is the task currently running |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + int $id, |
|
50 | + string $task_id, |
|
51 | + bool $enabled, |
|
52 | + Carbon $last_run, |
|
53 | + bool $last_result, |
|
54 | + CarbonInterval $frequency, |
|
55 | + int $nb_occurrences, |
|
56 | + bool $is_running |
|
57 | + ) { |
|
58 | + $this->id = $id; |
|
59 | + $this->task_id = $task_id; |
|
60 | + $this->enabled = $enabled; |
|
61 | + $this->last_run = $last_run; |
|
62 | + $this->last_result = $last_result; |
|
63 | + $this->frequency = $frequency; |
|
64 | + $this->nb_occurrences = $nb_occurrences; |
|
65 | + $this->is_running = $is_running; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get the schedule ID. |
|
70 | - * |
|
71 | - * @return int |
|
72 | - */ |
|
73 | - public function id(): int |
|
74 | - { |
|
75 | - return $this->id; |
|
76 | - } |
|
68 | + /** |
|
69 | + * Get the schedule ID. |
|
70 | + * |
|
71 | + * @return int |
|
72 | + */ |
|
73 | + public function id(): int |
|
74 | + { |
|
75 | + return $this->id; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get the task ID. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function taskId(): string |
|
84 | - { |
|
85 | - return $this->task_id; |
|
86 | - } |
|
78 | + /** |
|
79 | + * Get the task ID. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function taskId(): string |
|
84 | + { |
|
85 | + return $this->task_id; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Returns whether the schedule is enabled |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function isEnabled(): bool |
|
94 | - { |
|
95 | - return $this->enabled; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Returns whether the schedule is enabled |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function isEnabled(): bool |
|
94 | + { |
|
95 | + return $this->enabled; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Enable the schedule |
|
100 | - * |
|
101 | - * @return $this |
|
102 | - */ |
|
103 | - public function enable(): self |
|
104 | - { |
|
105 | - $this->enabled = true; |
|
106 | - return $this; |
|
107 | - } |
|
98 | + /** |
|
99 | + * Enable the schedule |
|
100 | + * |
|
101 | + * @return $this |
|
102 | + */ |
|
103 | + public function enable(): self |
|
104 | + { |
|
105 | + $this->enabled = true; |
|
106 | + return $this; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Disable the schedule |
|
111 | - * |
|
112 | - * @return $this |
|
113 | - */ |
|
114 | - public function disable(): self |
|
115 | - { |
|
116 | - $this->enabled = false; |
|
117 | - return $this; |
|
118 | - } |
|
109 | + /** |
|
110 | + * Disable the schedule |
|
111 | + * |
|
112 | + * @return $this |
|
113 | + */ |
|
114 | + public function disable(): self |
|
115 | + { |
|
116 | + $this->enabled = false; |
|
117 | + return $this; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Get the frequency of the schedule |
|
122 | - * |
|
123 | - * @return CarbonInterval |
|
124 | - */ |
|
125 | - public function frequency(): CarbonInterval |
|
126 | - { |
|
127 | - return $this->frequency; |
|
128 | - } |
|
120 | + /** |
|
121 | + * Get the frequency of the schedule |
|
122 | + * |
|
123 | + * @return CarbonInterval |
|
124 | + */ |
|
125 | + public function frequency(): CarbonInterval |
|
126 | + { |
|
127 | + return $this->frequency; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Set the frequency of the schedule |
|
132 | - * |
|
133 | - * @param CarbonInterval $frequency |
|
134 | - * @return $this |
|
135 | - */ |
|
136 | - public function setFrequency(CarbonInterval $frequency): self |
|
137 | - { |
|
138 | - $this->frequency = $frequency; |
|
139 | - return $this; |
|
140 | - } |
|
130 | + /** |
|
131 | + * Set the frequency of the schedule |
|
132 | + * |
|
133 | + * @param CarbonInterval $frequency |
|
134 | + * @return $this |
|
135 | + */ |
|
136 | + public function setFrequency(CarbonInterval $frequency): self |
|
137 | + { |
|
138 | + $this->frequency = $frequency; |
|
139 | + return $this; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Get the date/time of the last successful run. |
|
144 | - * |
|
145 | - * @return Carbon |
|
146 | - */ |
|
147 | - public function lastRunTime(): Carbon |
|
148 | - { |
|
149 | - return $this->last_run; |
|
150 | - } |
|
142 | + /** |
|
143 | + * Get the date/time of the last successful run. |
|
144 | + * |
|
145 | + * @return Carbon |
|
146 | + */ |
|
147 | + public function lastRunTime(): Carbon |
|
148 | + { |
|
149 | + return $this->last_run; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Set the last successful run date/time |
|
154 | - * |
|
155 | - * @param Carbon $last_run |
|
156 | - * @return $this |
|
157 | - */ |
|
158 | - public function setLastRunTime(Carbon $last_run): self |
|
159 | - { |
|
160 | - $this->last_run = $last_run; |
|
161 | - return $this; |
|
162 | - } |
|
152 | + /** |
|
153 | + * Set the last successful run date/time |
|
154 | + * |
|
155 | + * @param Carbon $last_run |
|
156 | + * @return $this |
|
157 | + */ |
|
158 | + public function setLastRunTime(Carbon $last_run): self |
|
159 | + { |
|
160 | + $this->last_run = $last_run; |
|
161 | + return $this; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Returns whether the last run was successful |
|
166 | - * |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function wasLastRunSuccess(): bool |
|
170 | - { |
|
171 | - return $this->last_result; |
|
172 | - } |
|
164 | + /** |
|
165 | + * Returns whether the last run was successful |
|
166 | + * |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function wasLastRunSuccess(): bool |
|
170 | + { |
|
171 | + return $this->last_result; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Set the last run result |
|
176 | - * |
|
177 | - * @param bool $last_result |
|
178 | - * @return $this |
|
179 | - */ |
|
180 | - public function setLastResult(bool $last_result): self |
|
181 | - { |
|
182 | - $this->last_result = $last_result; |
|
183 | - return $this; |
|
184 | - } |
|
174 | + /** |
|
175 | + * Set the last run result |
|
176 | + * |
|
177 | + * @param bool $last_result |
|
178 | + * @return $this |
|
179 | + */ |
|
180 | + public function setLastResult(bool $last_result): self |
|
181 | + { |
|
182 | + $this->last_result = $last_result; |
|
183 | + return $this; |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Get the number of remaining of occurrences of task runs. |
|
188 | - * Returns 0 if the tasks must be run indefinitely. |
|
189 | - * |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function remainingOccurences(): int |
|
193 | - { |
|
194 | - return $this->nb_occurrences; |
|
195 | - } |
|
186 | + /** |
|
187 | + * Get the number of remaining of occurrences of task runs. |
|
188 | + * Returns 0 if the tasks must be run indefinitely. |
|
189 | + * |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function remainingOccurences(): int |
|
193 | + { |
|
194 | + return $this->nb_occurrences; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Decrements the number of remaining occurences by 1. |
|
199 | - * The task will be disabled when the number reaches 0. |
|
200 | - * |
|
201 | - * @return $this |
|
202 | - */ |
|
203 | - public function decrementRemainingOccurences(): self |
|
204 | - { |
|
205 | - if ($this->nb_occurrences > 0) { |
|
206 | - $this->nb_occurrences--; |
|
207 | - if ($this->nb_occurrences == 0) { |
|
208 | - $this->disable(); |
|
209 | - } |
|
210 | - } |
|
211 | - return $this; |
|
212 | - } |
|
197 | + /** |
|
198 | + * Decrements the number of remaining occurences by 1. |
|
199 | + * The task will be disabled when the number reaches 0. |
|
200 | + * |
|
201 | + * @return $this |
|
202 | + */ |
|
203 | + public function decrementRemainingOccurences(): self |
|
204 | + { |
|
205 | + if ($this->nb_occurrences > 0) { |
|
206 | + $this->nb_occurrences--; |
|
207 | + if ($this->nb_occurrences == 0) { |
|
208 | + $this->disable(); |
|
209 | + } |
|
210 | + } |
|
211 | + return $this; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Set the number of remaining occurences of task runs. |
|
216 | - * |
|
217 | - * @param int $nb_occurrences |
|
218 | - * @return $this |
|
219 | - */ |
|
220 | - public function setRemainingOccurences(int $nb_occurrences): self |
|
221 | - { |
|
222 | - $this->nb_occurrences = $nb_occurrences; |
|
223 | - return $this; |
|
224 | - } |
|
214 | + /** |
|
215 | + * Set the number of remaining occurences of task runs. |
|
216 | + * |
|
217 | + * @param int $nb_occurrences |
|
218 | + * @return $this |
|
219 | + */ |
|
220 | + public function setRemainingOccurences(int $nb_occurrences): self |
|
221 | + { |
|
222 | + $this->nb_occurrences = $nb_occurrences; |
|
223 | + return $this; |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Returns whether the task is running |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - public function isRunning(): bool |
|
231 | - { |
|
232 | - return $this->is_running; |
|
233 | - } |
|
226 | + /** |
|
227 | + * Returns whether the task is running |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + public function isRunning(): bool |
|
231 | + { |
|
232 | + return $this->is_running; |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * Informs the schedule that the task is going to run |
|
237 | - * |
|
238 | - * @return $this |
|
239 | - */ |
|
240 | - public function startRunning(): self |
|
241 | - { |
|
242 | - $this->is_running = true; |
|
243 | - return $this; |
|
244 | - } |
|
235 | + /** |
|
236 | + * Informs the schedule that the task is going to run |
|
237 | + * |
|
238 | + * @return $this |
|
239 | + */ |
|
240 | + public function startRunning(): self |
|
241 | + { |
|
242 | + $this->is_running = true; |
|
243 | + return $this; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Informs the schedule that the task has stopped running. |
|
248 | - * @return $this |
|
249 | - */ |
|
250 | - public function stopRunning(): self |
|
251 | - { |
|
252 | - $this->is_running = false; |
|
253 | - return $this; |
|
254 | - } |
|
246 | + /** |
|
247 | + * Informs the schedule that the task has stopped running. |
|
248 | + * @return $this |
|
249 | + */ |
|
250 | + public function stopRunning(): self |
|
251 | + { |
|
252 | + $this->is_running = false; |
|
253 | + return $this; |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * Returns the schedule details as an associate array |
|
258 | - * |
|
259 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
260 | - * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool} |
|
261 | - */ |
|
262 | - public function toArray(): array |
|
263 | - { |
|
264 | - return [ |
|
265 | - 'id' => $this->id, |
|
266 | - 'task_id' => $this->task_id, |
|
267 | - 'enabled' => $this->enabled, |
|
268 | - 'last_run' => $this->last_run, |
|
269 | - 'last_result' => $this->last_result, |
|
270 | - 'frequency' => $this->frequency, |
|
271 | - 'nb_occurrences' => $this->nb_occurrences, |
|
272 | - 'is_running' => $this->is_running |
|
273 | - ]; |
|
274 | - } |
|
256 | + /** |
|
257 | + * Returns the schedule details as an associate array |
|
258 | + * |
|
259 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
260 | + * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool} |
|
261 | + */ |
|
262 | + public function toArray(): array |
|
263 | + { |
|
264 | + return [ |
|
265 | + 'id' => $this->id, |
|
266 | + 'task_id' => $this->task_id, |
|
267 | + 'enabled' => $this->enabled, |
|
268 | + 'last_run' => $this->last_run, |
|
269 | + 'last_result' => $this->last_result, |
|
270 | + 'frequency' => $this->frequency, |
|
271 | + 'nb_occurrences' => $this->nb_occurrences, |
|
272 | + 'is_running' => $this->is_running |
|
273 | + ]; |
|
274 | + } |
|
275 | 275 | } |