Passed
Branch feature/2.1-geodispersion-dev (38d49e)
by Jonathan
04:17
created
src/Webtrees/Module/IsSourced/IsSourcedModule.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -30,92 +30,92 @@
 block discarded – undo
30 30
  * IsSourced Module
31 31
  */
32 32
 class IsSourcedModule extends AbstractModule implements
33
-    ModuleMyArtJaubInterface,
34
-    ModuleGlobalInterface,
35
-    ModuleSidebarInterface
33
+	ModuleMyArtJaubInterface,
34
+	ModuleGlobalInterface,
35
+	ModuleSidebarInterface
36 36
 {
37
-    use ModuleMyArtJaubTrait;
38
-    use ModuleGlobalTrait;
39
-    use ModuleSidebarTrait;
37
+	use ModuleMyArtJaubTrait;
38
+	use ModuleGlobalTrait;
39
+	use ModuleSidebarTrait;
40 40
 
41
-    /**
42
-     * {@inheritDoc}
43
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
44
-     */
45
-    public function title(): string
46
-    {
47
-        return I18N::translate('Sourced events');
48
-    }
41
+	/**
42
+	 * {@inheritDoc}
43
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
44
+	 */
45
+	public function title(): string
46
+	{
47
+		return I18N::translate('Sourced events');
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
53
-     */
54
-    public function description(): string
55
-    {
56
-        return I18N::translate('Indicate if events related to an record are sourced.');
57
-    }
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
53
+	 */
54
+	public function description(): string
55
+	{
56
+		return I18N::translate('Indicate if events related to an record are sourced.');
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
62
-     */
63
-    public function customModuleVersion(): string
64
-    {
65
-        return '2.1.0-v.1';
66
-    }
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
62
+	 */
63
+	public function customModuleVersion(): string
64
+	{
65
+		return '2.1.0-v.1';
66
+	}
67 67
 
68
-    /**
69
-     * {@inheritDoc}
70
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
71
-     */
72
-    public function headContent(): string
73
-    {
74
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
75
-    }
68
+	/**
69
+	 * {@inheritDoc}
70
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
71
+	 */
72
+	public function headContent(): string
73
+	{
74
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
75
+	}
76 76
 
77
-    /**
78
-     * {@inheritDoc}
79
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
80
-     */
81
-    public function bodyContent(): string
82
-    {
83
-        return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
84
-    }
77
+	/**
78
+	 * {@inheritDoc}
79
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
80
+	 */
81
+	public function bodyContent(): string
82
+	{
83
+		return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
84
+	}
85 85
 
86
-    /**
87
-     * {@inheritDoc}
88
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
89
-     */
90
-    public function hasSidebarContent(Individual $individual): bool
91
-    {
92
-        return true;
93
-    }
86
+	/**
87
+	 * {@inheritDoc}
88
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
89
+	 */
90
+	public function hasSidebarContent(Individual $individual): bool
91
+	{
92
+		return true;
93
+	}
94 94
 
95
-    /**
96
-     * {@inheritDoc}
97
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
98
-     */
99
-    public function getSidebarContent(Individual $individual): string
100
-    {
101
-        /** @var SourceStatusService $source_status_service */
102
-        $source_status_service = app(SourceStatusService::class);
95
+	/**
96
+	 * {@inheritDoc}
97
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
98
+	 */
99
+	public function getSidebarContent(Individual $individual): string
100
+	{
101
+		/** @var SourceStatusService $source_status_service */
102
+		$source_status_service = app(SourceStatusService::class);
103 103
 
104
-        $spouse_families_status = $individual->spouseFamilies()->map(
105
-            function (Family $sfamily) use ($source_status_service): array {
106
-                return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107
-            }
108
-        )->filter(function (array $item): bool {
109
-            return $item[1]->isSet();
110
-        });
104
+		$spouse_families_status = $individual->spouseFamilies()->map(
105
+			function (Family $sfamily) use ($source_status_service): array {
106
+				return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107
+			}
108
+		)->filter(function (array $item): bool {
109
+			return $item[1]->isSet();
110
+		});
111 111
 
112
-        return view($this->name() . '::sidebar/content', [
113
-            'module_name'               => $this->name(),
114
-            'individual'                =>  $individual,
115
-            'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
116
-            'source_status_birth'       =>  $source_status_service->sourceStatusForBirth($individual),
117
-            'source_status_marriages'   =>  $spouse_families_status,
118
-            'source_status_death'       =>  $source_status_service->sourceStatusForDeath($individual)
119
-        ]);
120
-    }
112
+		return view($this->name() . '::sidebar/content', [
113
+			'module_name'               => $this->name(),
114
+			'individual'                =>  $individual,
115
+			'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
116
+			'source_status_birth'       =>  $source_status_service->sourceStatusForBirth($individual),
117
+			'source_status_marriages'   =>  $spouse_families_status,
118
+			'source_status_death'       =>  $source_status_service->sourceStatusForDeath($individual)
119
+		]);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function headContent(): string
73 73
     {
74
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
74
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
75 75
     }
76 76
 
77 77
     /**
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function bodyContent(): string
82 82
     {
83
-        return '<script src="' . $this->assetUrl('js/issourced.min.js') . '"></script>';
83
+        return '<script src="'.$this->assetUrl('js/issourced.min.js').'"></script>';
84 84
     }
85 85
 
86 86
     /**
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
         $source_status_service = app(SourceStatusService::class);
103 103
 
104 104
         $spouse_families_status = $individual->spouseFamilies()->map(
105
-            function (Family $sfamily) use ($source_status_service): array {
106
-                return [ $sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
105
+            function(Family $sfamily) use ($source_status_service): array {
106
+                return [$sfamily, $source_status_service->sourceStatusForMarriage($sfamily)];
107 107
             }
108
-        )->filter(function (array $item): bool {
108
+        )->filter(function(array $item): bool {
109 109
             return $item[1]->isSet();
110 110
         });
111 111
 
112
-        return view($this->name() . '::sidebar/content', [
112
+        return view($this->name().'::sidebar/content', [
113 113
             'module_name'               => $this->name(),
114 114
             'individual'                =>  $individual,
115 115
             'source_status_individual'  =>  $source_status_service->sourceStatusForRecord($individual),
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/Data/SourceStatus.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -22,137 +22,137 @@
 block discarded – undo
22 22
  */
23 23
 class SourceStatus
24 24
 {
25
-    /**
26
-     * @var boolean $source_exist
27
-     */
28
-    private $source_exist = false;
29
-
30
-    /**
31
-     * @var boolean $has_document
32
-     */
33
-    private $has_document = false;
34
-
35
-    /**
36
-     * Return whether the SourceStatus object contains relevant data.
37
-     *
38
-     * @return bool
39
-     */
40
-    public function isSet(): bool
41
-    {
42
-        return true;
43
-    }
44
-
45
-    /**
46
-     * Returns whether the record contains a source.
47
-     *
48
-     * @return bool
49
-     */
50
-    public function hasSource(): bool
51
-    {
52
-        return $this->source_exist;
53
-    }
54
-
55
-    /**
56
-     *  Set whether the record contains a source.
57
-     *
58
-     * @param bool $source_exist
59
-     * @return self
60
-     */
61
-    public function setHasSource(bool $source_exist): self
62
-    {
63
-        $this->source_exist = $source_exist;
64
-        return $this;
65
-    }
66
-
67
-    /**
68
-     * Combine whether the record contains a source with the previous status.
69
-     *
70
-     * @param bool $source_exist
71
-     * @return self
72
-     */
73
-    public function addHasSource(bool $source_exist): self
74
-    {
75
-        $this->source_exist = $this->source_exist || $source_exist;
76
-        return $this;
77
-    }
78
-
79
-    /**
80
-     * Return whether the source citation is supported by a document.
81
-     * Uses the _ACT tag from the MyArtJaub Certificates module.
82
-     *
83
-     * @return bool
84
-     */
85
-    public function hasSupportingDocument(): bool
86
-    {
87
-        return $this->hasSource() && $this->has_document;
88
-    }
89
-
90
-    /**
91
-     * Set whether the source citation is supported by a document.
92
-     *
93
-     * @param bool $has_document
94
-     * @return self
95
-     */
96
-    public function setHasSupportingDocument(bool $has_document): self
97
-    {
98
-        $this->has_document = $has_document;
99
-        return $this;
100
-    }
101
-
102
-    /**
103
-     * Combine whether the source citation is supported by a document with the previous status.
104
-     *
105
-     * @param bool $has_document
106
-     * @return self
107
-     */
108
-    public function addHasSupportingDocument(bool $has_document): self
109
-    {
110
-        $this->has_document = $this->has_document || $has_document;
111
-        return $this;
112
-    }
113
-
114
-    /**
115
-     * Check whether all possible criteria for defining a sourced element have been met.
116
-     *
117
-     * @return bool
118
-     */
119
-    public function isFullySourced(): bool
120
-    {
121
-        return $this->hasSupportingDocument();
122
-    }
123
-
124
-    /**
125
-     * Get the label to display to describe the source status.
126
-     *
127
-     * @param string $context
128
-     * @return string
129
-     */
130
-    public function label(string $context): string
131
-    {
132
-        $context_label = Registry::elementFactory()->make($context)->label();
133
-
134
-        if (!$this->hasSource()) {
135
-            return I18N::translate('%s not sourced', $context_label);
136
-        }
137
-
138
-        if ($this->hasSupportingDocument()) {
139
-            return I18N::translate('%s sourced with a certificate', $context_label);
140
-        }
141
-
142
-        return I18N::translate('%s sourced', $context_label);
143
-    }
144
-
145
-    /**
146
-     * Return an element combining properties of the current object with another SourceStatus.
147
-     * Do not use the initial object anymore, it may not appropriately describe the status anymore.
148
-     *
149
-     * @param SourceStatus $other
150
-     * @return self
151
-     */
152
-    public function combineWith(SourceStatus $other): self
153
-    {
154
-        $this->addHasSource($other->hasSource());
155
-        $this->addHasSupportingDocument($other->hasSource());
156
-        return $this;
157
-    }
25
+	/**
26
+	 * @var boolean $source_exist
27
+	 */
28
+	private $source_exist = false;
29
+
30
+	/**
31
+	 * @var boolean $has_document
32
+	 */
33
+	private $has_document = false;
34
+
35
+	/**
36
+	 * Return whether the SourceStatus object contains relevant data.
37
+	 *
38
+	 * @return bool
39
+	 */
40
+	public function isSet(): bool
41
+	{
42
+		return true;
43
+	}
44
+
45
+	/**
46
+	 * Returns whether the record contains a source.
47
+	 *
48
+	 * @return bool
49
+	 */
50
+	public function hasSource(): bool
51
+	{
52
+		return $this->source_exist;
53
+	}
54
+
55
+	/**
56
+	 *  Set whether the record contains a source.
57
+	 *
58
+	 * @param bool $source_exist
59
+	 * @return self
60
+	 */
61
+	public function setHasSource(bool $source_exist): self
62
+	{
63
+		$this->source_exist = $source_exist;
64
+		return $this;
65
+	}
66
+
67
+	/**
68
+	 * Combine whether the record contains a source with the previous status.
69
+	 *
70
+	 * @param bool $source_exist
71
+	 * @return self
72
+	 */
73
+	public function addHasSource(bool $source_exist): self
74
+	{
75
+		$this->source_exist = $this->source_exist || $source_exist;
76
+		return $this;
77
+	}
78
+
79
+	/**
80
+	 * Return whether the source citation is supported by a document.
81
+	 * Uses the _ACT tag from the MyArtJaub Certificates module.
82
+	 *
83
+	 * @return bool
84
+	 */
85
+	public function hasSupportingDocument(): bool
86
+	{
87
+		return $this->hasSource() && $this->has_document;
88
+	}
89
+
90
+	/**
91
+	 * Set whether the source citation is supported by a document.
92
+	 *
93
+	 * @param bool $has_document
94
+	 * @return self
95
+	 */
96
+	public function setHasSupportingDocument(bool $has_document): self
97
+	{
98
+		$this->has_document = $has_document;
99
+		return $this;
100
+	}
101
+
102
+	/**
103
+	 * Combine whether the source citation is supported by a document with the previous status.
104
+	 *
105
+	 * @param bool $has_document
106
+	 * @return self
107
+	 */
108
+	public function addHasSupportingDocument(bool $has_document): self
109
+	{
110
+		$this->has_document = $this->has_document || $has_document;
111
+		return $this;
112
+	}
113
+
114
+	/**
115
+	 * Check whether all possible criteria for defining a sourced element have been met.
116
+	 *
117
+	 * @return bool
118
+	 */
119
+	public function isFullySourced(): bool
120
+	{
121
+		return $this->hasSupportingDocument();
122
+	}
123
+
124
+	/**
125
+	 * Get the label to display to describe the source status.
126
+	 *
127
+	 * @param string $context
128
+	 * @return string
129
+	 */
130
+	public function label(string $context): string
131
+	{
132
+		$context_label = Registry::elementFactory()->make($context)->label();
133
+
134
+		if (!$this->hasSource()) {
135
+			return I18N::translate('%s not sourced', $context_label);
136
+		}
137
+
138
+		if ($this->hasSupportingDocument()) {
139
+			return I18N::translate('%s sourced with a certificate', $context_label);
140
+		}
141
+
142
+		return I18N::translate('%s sourced', $context_label);
143
+	}
144
+
145
+	/**
146
+	 * Return an element combining properties of the current object with another SourceStatus.
147
+	 * Do not use the initial object anymore, it may not appropriately describe the status anymore.
148
+	 *
149
+	 * @param SourceStatus $other
150
+	 * @return self
151
+	 */
152
+	public function combineWith(SourceStatus $other): self
153
+	{
154
+		$this->addHasSource($other->hasSource());
155
+		$this->addHasSupportingDocument($other->hasSource());
156
+		return $this;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/Data/FactSourceStatus.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -22,211 +22,211 @@
 block discarded – undo
22 22
  */
23 23
 class FactSourceStatus extends SourceStatus
24 24
 {
25
-    /**
26
-     * @var boolean $has_date
27
-     */
28
-    private $has_date = false;
29
-
30
-    /**
31
-     * @var boolean $has_precise_date
32
-     */
33
-    private $has_precise_date = false;
34
-
35
-    /**
36
-     * @var boolean $has_source_date
37
-     */
38
-    private $has_source_date = false;
39
-
40
-    /**
41
-     * @var boolean $source_date_match
42
-     */
43
-    private $source_date_match = false;
44
-
45
-    /**
46
-     * Return whether the fact is dated.
47
-     *
48
-     * @return bool
49
-     */
50
-    public function factHasDate(): bool
51
-    {
52
-        return $this->has_date;
53
-    }
54
-
55
-    /**
56
-     * Set whether the fact is dated.
57
-     *
58
-     * @param bool $has_date
59
-     * @return self
60
-     */
61
-    public function setFactHasDate(bool $has_date): self
62
-    {
63
-        $this->has_date = $has_date;
64
-        return $this;
65
-    }
66
-
67
-    /**
68
-     * Combinate whether the fact is dated with the previous status.
69
-     *
70
-     * @param bool $has_date
71
-     * @return self
72
-     */
73
-    public function addFactHasDate(bool $has_date): self
74
-    {
75
-        $this->has_date = $this->has_date || $has_date;
76
-        return $this;
77
-    }
78
-
79
-    /**
80
-     * Return whether the fact is dated with a precise day.
81
-     * Any date modifier will be considered as not precise.
82
-     * A month or year will be considered as not precise.
83
-     *
84
-     * @return bool
85
-     */
86
-    public function factHasPreciseDate(): bool
87
-    {
88
-        return $this->has_date && $this->has_precise_date;
89
-    }
90
-
91
-    /**
92
-     * Set whather the fact is dated with a precise day.
93
-     *
94
-     * @param bool $has_precise_date
95
-     * @return self
96
-     */
97
-    public function setFactHasPreciseDate(bool $has_precise_date): self
98
-    {
99
-        $this->has_precise_date = $has_precise_date;
100
-        return $this;
101
-    }
102
-
103
-    public function addFactHasPreciseDate(bool $has_precise_date): self
104
-    {
105
-        $this->has_precise_date = $this->has_precise_date || $has_precise_date;
106
-        return $this;
107
-    }
108
-
109
-    /**
110
-     * Return whether the source citation is dated.
111
-     *
112
-     * @return bool
113
-     */
114
-    public function sourceHasDate(): bool
115
-    {
116
-        return $this->has_source_date;
117
-    }
118
-
119
-    /**
120
-     * Set whether the source citation is dated.
121
-     *
122
-     * @param bool $has_source_date
123
-     * @return self
124
-     */
125
-    public function setSourceHasDate(bool $has_source_date): self
126
-    {
127
-        $this->has_source_date = $has_source_date;
128
-        return $this;
129
-    }
130
-
131
-    /**
132
-     * Combine whether the source citation is dated with the previous status.
133
-     *
134
-     * @param bool $has_source_date
135
-     * @return self
136
-     */
137
-    public function addSourceHasDate(bool $has_source_date): self
138
-    {
139
-        $this->has_source_date = $this->has_source_date || $has_source_date;
140
-        return $this;
141
-    }
142
-
143
-    /**
144
-     * Return whether the source citation date is close to the fact date.
145
-     *
146
-     * @return bool
147
-     */
148
-    public function sourceMatchesFactDate(): bool
149
-    {
150
-        return $this->has_precise_date && $this->has_source_date && $this->source_date_match;
151
-    }
152
-
153
-    /**
154
-     * Set whether the source citation date is close to the fact date.
155
-     *
156
-     * @param bool $source_date_match
157
-     * @return self
158
-     */
159
-    public function setSourceMatchesFactDate(bool $source_date_match): self
160
-    {
161
-        $this->source_date_match = $source_date_match;
162
-        return $this;
163
-    }
164
-
165
-    /**
166
-     * Combine whether the source citation date is close to the fact date with the previous status.
167
-     *
168
-     * @param bool $source_date_match
169
-     * @return self
170
-     */
171
-    public function addSourceMatchesFactDate(bool $source_date_match): self
172
-    {
173
-        $this->source_date_match = $this->source_date_match || $source_date_match;
174
-        return $this;
175
-    }
176
-
177
-    /**
178
-     * {@inheritDoc}
179
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isFullySourced()
180
-     */
181
-    public function isFullySourced(): bool
182
-    {
183
-        return parent::isFullySourced() && $this->sourceMatchesFactDate();
184
-    }
185
-
186
-    /**
187
-     * {@inheritDoc}
188
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::label()
189
-     */
190
-    public function label(string $context): string
191
-    {
192
-        $context_label = Registry::elementFactory()->make($context)->label();
193
-
194
-        if ($this->factHasPreciseDate()) {
195
-            if ($this->hasSource()) {
196
-                if ($this->hasSupportingDocument()) {
197
-                    if ($this->sourceMatchesFactDate()) {
198
-                        return I18N::translate('%s sourced with exact certificate', $context_label);
199
-                    } else {
200
-                        return I18N::translate('%s sourced with a certificate', $context_label);
201
-                    }
202
-                }
203
-
204
-                if ($this->sourceMatchesFactDate()) {
205
-                    return I18N::translate('%s precisely sourced', $context_label);
206
-                }
207
-                return I18N::translate('%s sourced', $context_label);
208
-            }
209
-            return I18N::translate('%s not sourced', $context_label);
210
-        }
211
-
212
-        if ($this->factHasDate()) {
213
-            return I18N::translate('%s not precise', $context_label);
214
-        }
215
-        return I18N::translate('%s not found', $context_label);
216
-    }
217
-
218
-    /**
219
-     * {@inheritDoc}
220
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::combineWith()
221
-     */
222
-    public function combineWith(SourceStatus $other): SourceStatus
223
-    {
224
-        if ($other instanceof FactSourceStatus) {
225
-            $this->addFactHasDate($other->factHasDate());
226
-            $this->addFactHasPreciseDate($other->factHasPreciseDate());
227
-            $this->addSourceHasDate($other->sourceHasDate());
228
-            $this->addSourceMatchesFactDate($other->sourceMatchesFactDate());
229
-        }
230
-        return parent::combineWith($other);
231
-    }
25
+	/**
26
+	 * @var boolean $has_date
27
+	 */
28
+	private $has_date = false;
29
+
30
+	/**
31
+	 * @var boolean $has_precise_date
32
+	 */
33
+	private $has_precise_date = false;
34
+
35
+	/**
36
+	 * @var boolean $has_source_date
37
+	 */
38
+	private $has_source_date = false;
39
+
40
+	/**
41
+	 * @var boolean $source_date_match
42
+	 */
43
+	private $source_date_match = false;
44
+
45
+	/**
46
+	 * Return whether the fact is dated.
47
+	 *
48
+	 * @return bool
49
+	 */
50
+	public function factHasDate(): bool
51
+	{
52
+		return $this->has_date;
53
+	}
54
+
55
+	/**
56
+	 * Set whether the fact is dated.
57
+	 *
58
+	 * @param bool $has_date
59
+	 * @return self
60
+	 */
61
+	public function setFactHasDate(bool $has_date): self
62
+	{
63
+		$this->has_date = $has_date;
64
+		return $this;
65
+	}
66
+
67
+	/**
68
+	 * Combinate whether the fact is dated with the previous status.
69
+	 *
70
+	 * @param bool $has_date
71
+	 * @return self
72
+	 */
73
+	public function addFactHasDate(bool $has_date): self
74
+	{
75
+		$this->has_date = $this->has_date || $has_date;
76
+		return $this;
77
+	}
78
+
79
+	/**
80
+	 * Return whether the fact is dated with a precise day.
81
+	 * Any date modifier will be considered as not precise.
82
+	 * A month or year will be considered as not precise.
83
+	 *
84
+	 * @return bool
85
+	 */
86
+	public function factHasPreciseDate(): bool
87
+	{
88
+		return $this->has_date && $this->has_precise_date;
89
+	}
90
+
91
+	/**
92
+	 * Set whather the fact is dated with a precise day.
93
+	 *
94
+	 * @param bool $has_precise_date
95
+	 * @return self
96
+	 */
97
+	public function setFactHasPreciseDate(bool $has_precise_date): self
98
+	{
99
+		$this->has_precise_date = $has_precise_date;
100
+		return $this;
101
+	}
102
+
103
+	public function addFactHasPreciseDate(bool $has_precise_date): self
104
+	{
105
+		$this->has_precise_date = $this->has_precise_date || $has_precise_date;
106
+		return $this;
107
+	}
108
+
109
+	/**
110
+	 * Return whether the source citation is dated.
111
+	 *
112
+	 * @return bool
113
+	 */
114
+	public function sourceHasDate(): bool
115
+	{
116
+		return $this->has_source_date;
117
+	}
118
+
119
+	/**
120
+	 * Set whether the source citation is dated.
121
+	 *
122
+	 * @param bool $has_source_date
123
+	 * @return self
124
+	 */
125
+	public function setSourceHasDate(bool $has_source_date): self
126
+	{
127
+		$this->has_source_date = $has_source_date;
128
+		return $this;
129
+	}
130
+
131
+	/**
132
+	 * Combine whether the source citation is dated with the previous status.
133
+	 *
134
+	 * @param bool $has_source_date
135
+	 * @return self
136
+	 */
137
+	public function addSourceHasDate(bool $has_source_date): self
138
+	{
139
+		$this->has_source_date = $this->has_source_date || $has_source_date;
140
+		return $this;
141
+	}
142
+
143
+	/**
144
+	 * Return whether the source citation date is close to the fact date.
145
+	 *
146
+	 * @return bool
147
+	 */
148
+	public function sourceMatchesFactDate(): bool
149
+	{
150
+		return $this->has_precise_date && $this->has_source_date && $this->source_date_match;
151
+	}
152
+
153
+	/**
154
+	 * Set whether the source citation date is close to the fact date.
155
+	 *
156
+	 * @param bool $source_date_match
157
+	 * @return self
158
+	 */
159
+	public function setSourceMatchesFactDate(bool $source_date_match): self
160
+	{
161
+		$this->source_date_match = $source_date_match;
162
+		return $this;
163
+	}
164
+
165
+	/**
166
+	 * Combine whether the source citation date is close to the fact date with the previous status.
167
+	 *
168
+	 * @param bool $source_date_match
169
+	 * @return self
170
+	 */
171
+	public function addSourceMatchesFactDate(bool $source_date_match): self
172
+	{
173
+		$this->source_date_match = $this->source_date_match || $source_date_match;
174
+		return $this;
175
+	}
176
+
177
+	/**
178
+	 * {@inheritDoc}
179
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isFullySourced()
180
+	 */
181
+	public function isFullySourced(): bool
182
+	{
183
+		return parent::isFullySourced() && $this->sourceMatchesFactDate();
184
+	}
185
+
186
+	/**
187
+	 * {@inheritDoc}
188
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::label()
189
+	 */
190
+	public function label(string $context): string
191
+	{
192
+		$context_label = Registry::elementFactory()->make($context)->label();
193
+
194
+		if ($this->factHasPreciseDate()) {
195
+			if ($this->hasSource()) {
196
+				if ($this->hasSupportingDocument()) {
197
+					if ($this->sourceMatchesFactDate()) {
198
+						return I18N::translate('%s sourced with exact certificate', $context_label);
199
+					} else {
200
+						return I18N::translate('%s sourced with a certificate', $context_label);
201
+					}
202
+				}
203
+
204
+				if ($this->sourceMatchesFactDate()) {
205
+					return I18N::translate('%s precisely sourced', $context_label);
206
+				}
207
+				return I18N::translate('%s sourced', $context_label);
208
+			}
209
+			return I18N::translate('%s not sourced', $context_label);
210
+		}
211
+
212
+		if ($this->factHasDate()) {
213
+			return I18N::translate('%s not precise', $context_label);
214
+		}
215
+		return I18N::translate('%s not found', $context_label);
216
+	}
217
+
218
+	/**
219
+	 * {@inheritDoc}
220
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::combineWith()
221
+	 */
222
+	public function combineWith(SourceStatus $other): SourceStatus
223
+	{
224
+		if ($other instanceof FactSourceStatus) {
225
+			$this->addFactHasDate($other->factHasDate());
226
+			$this->addFactHasPreciseDate($other->factHasPreciseDate());
227
+			$this->addSourceHasDate($other->sourceHasDate());
228
+			$this->addSourceMatchesFactDate($other->sourceMatchesFactDate());
229
+		}
230
+		return parent::combineWith($other);
231
+	}
232 232
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/Data/NullFactSourceStatus.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,21 +19,21 @@
 block discarded – undo
19 19
  */
20 20
 class NullFactSourceStatus extends FactSourceStatus
21 21
 {
22
-    /**
23
-     * {@inheritDoc}
24
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet()
25
-     */
26
-    public function isSet(): bool
27
-    {
28
-        return false;
29
-    }
22
+	/**
23
+	 * {@inheritDoc}
24
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet()
25
+	 */
26
+	public function isSet(): bool
27
+	{
28
+		return false;
29
+	}
30 30
 
31
-    /**
32
-     * {@inheritDoc}
33
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith()
34
-     */
35
-    public function combineWith(SourceStatus $other): SourceStatus
36
-    {
37
-        return $other;
38
-    }
31
+	/**
32
+	 * {@inheritDoc}
33
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith()
34
+	 */
35
+	public function combineWith(SourceStatus $other): SourceStatus
36
+	{
37
+		return $other;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Http/RequestHandlers/MatomoStats.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -31,64 +31,64 @@
 block discarded – undo
31 31
  */
32 32
 class MatomoStats implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
34
+	use ViewResponseTrait;
35 35
 
36
-    /**
37
-     * @var WelcomeBlockModule|null $module
38
-     */
39
-    private $module;
36
+	/**
37
+	 * @var WelcomeBlockModule|null $module
38
+	 */
39
+	private $module;
40 40
 
41
-    /**
42
-     * @var MatomoStatsService $matomo_service
43
-     */
44
-    private $matomo_service;
41
+	/**
42
+	 * @var MatomoStatsService $matomo_service
43
+	 */
44
+	private $matomo_service;
45 45
 
46
-    /**
47
-     * Constructor for MatomoStats request handler
48
-     * @param ModuleService $module_service
49
-     * @param MatomoStatsService $matomo_service
50
-     */
51
-    public function __construct(
52
-        ModuleService $module_service,
53
-        MatomoStatsService $matomo_service
54
-    ) {
55
-        $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
56
-        $this->matomo_service = $matomo_service;
57
-    }
46
+	/**
47
+	 * Constructor for MatomoStats request handler
48
+	 * @param ModuleService $module_service
49
+	 * @param MatomoStatsService $matomo_service
50
+	 */
51
+	public function __construct(
52
+		ModuleService $module_service,
53
+		MatomoStatsService $matomo_service
54
+	) {
55
+		$this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
56
+		$this->matomo_service = $matomo_service;
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
-     */
63
-    public function handle(ServerRequestInterface $request): ResponseInterface
64
-    {
65
-        $this->layout = 'layouts/ajax';
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
+	 */
63
+	public function handle(ServerRequestInterface $request): ResponseInterface
64
+	{
65
+		$this->layout = 'layouts/ajax';
66 66
 
67
-        if ($this->module === null) {
68
-            return $this->viewResponse('errors/unhandled-exception', [
69
-                'error' => 'The attached module could not be found.'
70
-            ], StatusCodeInterface::STATUS_NOT_FOUND);
71
-        }
67
+		if ($this->module === null) {
68
+			return $this->viewResponse('errors/unhandled-exception', [
69
+				'error' => 'The attached module could not be found.'
70
+			], StatusCodeInterface::STATUS_NOT_FOUND);
71
+		}
72 72
 
73
-        $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
74
-        $nb_visits_year = $nb_visits_today = null;
73
+		$block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
74
+		$nb_visits_year = $nb_visits_today = null;
75 75
 
76
-        try {
77
-            if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
78
-                $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
79
-                $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
80
-                    + $nb_visits_today;
81
-            }
82
-        } catch (Throwable $ex) {
83
-            return $this->viewResponse('errors/unhandled-exception', [
84
-                'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
85
-                    (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
86
-            ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
87
-        }
76
+		try {
77
+			if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
78
+				$nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
79
+				$nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
80
+					+ $nb_visits_today;
81
+			}
82
+		} catch (Throwable $ex) {
83
+			return $this->viewResponse('errors/unhandled-exception', [
84
+				'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
85
+					(Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
86
+			], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
87
+		}
88 88
 
89
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
90
-            'visits_year'   =>  $nb_visits_year,
91
-            'visits_today'  =>  $nb_visits_today
92
-        ]);
93
-    }
89
+		return $this->viewResponse($this->module->name() . '::matomo-stats', [
90
+			'visits_year'   =>  $nb_visits_year,
91
+			'visits_today'  =>  $nb_visits_today
92
+		]);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,12 +81,12 @@
 block discarded – undo
81 81
             }
82 82
         } catch (Throwable $ex) {
83 83
             return $this->viewResponse('errors/unhandled-exception', [
84
-                'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
84
+                'error' => I18N::translate('Error while retrieving Matomo statistics: ').
85 85
                     (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
86 86
             ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
87 87
         }
88 88
 
89
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
89
+        return $this->viewResponse($this->module->name().'::matomo-stats', [
90 90
             'visits_year'   =>  $nb_visits_year,
91 91
             'visits_today'  =>  $nb_visits_today
92 92
         ]);
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Services/MatomoStatsService.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -29,93 +29,93 @@
 block discarded – undo
29 29
 class MatomoStatsService
30 30
 {
31 31
 
32
-    /**
33
-     * Returns the number of visits for the current year (up to the day before).
34
-     * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
35
-     *
36
-     * @param WelcomeBlockModule $module
37
-     * @param int $block_id
38
-     * @return int|NULL
39
-     */
40
-    public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
41
-    {
42
-        return Registry::cache()->file()->remember(
43
-            $module->name() . '-matomovisits-yearly-' . $block_id,
44
-            function () use ($module, $block_id): ?int {
45
-                $visits_year = $this->visits($module, $block_id, 'year');
46
-                if ($visits_year === null) {
47
-                    return null;
48
-                }
49
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
32
+	/**
33
+	 * Returns the number of visits for the current year (up to the day before).
34
+	 * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
35
+	 *
36
+	 * @param WelcomeBlockModule $module
37
+	 * @param int $block_id
38
+	 * @return int|NULL
39
+	 */
40
+	public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
41
+	{
42
+		return Registry::cache()->file()->remember(
43
+			$module->name() . '-matomovisits-yearly-' . $block_id,
44
+			function () use ($module, $block_id): ?int {
45
+				$visits_year = $this->visits($module, $block_id, 'year');
46
+				if ($visits_year === null) {
47
+					return null;
48
+				}
49
+				$visits_today = (int) $this->visits($module, $block_id, 'day');
50 50
 
51
-                return $visits_year - $visits_today;
52
-            },
53
-            Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
54
-        );
55
-    }
51
+				return $visits_year - $visits_today;
52
+			},
53
+			Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
54
+		);
55
+	}
56 56
 
57
-    /**
58
-     * Returns the number of visits for the current day.
59
-     *
60
-     * @param WelcomeBlockModule $module
61
-     * @param int $block_id
62
-     * @return int|NULL
63
-     */
64
-    public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
65
-    {
66
-        return Registry::cache()->array()->remember(
67
-            $module->name() . '-matomovisits-daily-' . $block_id,
68
-            function () use ($module, $block_id): ?int {
69
-                return $this->visits($module, $block_id, 'day');
70
-            }
71
-        );
72
-    }
57
+	/**
58
+	 * Returns the number of visits for the current day.
59
+	 *
60
+	 * @param WelcomeBlockModule $module
61
+	 * @param int $block_id
62
+	 * @return int|NULL
63
+	 */
64
+	public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
65
+	{
66
+		return Registry::cache()->array()->remember(
67
+			$module->name() . '-matomovisits-daily-' . $block_id,
68
+			function () use ($module, $block_id): ?int {
69
+				return $this->visits($module, $block_id, 'day');
70
+			}
71
+		);
72
+	}
73 73
 
74
-    /**
75
-     * Invoke the Matomo API to retrieve the number of visits over a period.
76
-     *
77
-     * @param WelcomeBlockModule $module
78
-     * @param int $block_id
79
-     * @param string $period
80
-     * @return int|NULL
81
-     */
82
-    protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
83
-    {
84
-        $settings = $module->matomoSettings($block_id);
74
+	/**
75
+	 * Invoke the Matomo API to retrieve the number of visits over a period.
76
+	 *
77
+	 * @param WelcomeBlockModule $module
78
+	 * @param int $block_id
79
+	 * @param string $period
80
+	 * @return int|NULL
81
+	 */
82
+	protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
83
+	{
84
+		$settings = $module->matomoSettings($block_id);
85 85
 
86
-        if (
87
-            $settings['matomo_enabled'] === true
88
-            && mb_strlen($settings['matomo_url']) > 0
89
-            && mb_strlen($settings['matomo_token']) > 0
90
-            && $settings['matomo_siteid'] > 0
91
-        ) {
92
-            try {
93
-                $http_client = new Client([
94
-                    RequestOptions::TIMEOUT => 30
95
-                ]);
86
+		if (
87
+			$settings['matomo_enabled'] === true
88
+			&& mb_strlen($settings['matomo_url']) > 0
89
+			&& mb_strlen($settings['matomo_token']) > 0
90
+			&& $settings['matomo_siteid'] > 0
91
+		) {
92
+			try {
93
+				$http_client = new Client([
94
+					RequestOptions::TIMEOUT => 30
95
+				]);
96 96
 
97
-                $response = $http_client->get($settings['matomo_url'], [
98
-                    'query' =>  [
99
-                        'module'    =>  'API',
100
-                        'method'    =>  'VisitsSummary.getVisits',
101
-                        'idSite'    =>  $settings['matomo_siteid'],
102
-                        'period'    =>  $period,
103
-                        'date'      =>  'today',
104
-                        'token_auth' =>  $settings['matomo_token'],
105
-                        'format'    =>  'json'
106
-                    ]
107
-                ]);
97
+				$response = $http_client->get($settings['matomo_url'], [
98
+					'query' =>  [
99
+						'module'    =>  'API',
100
+						'method'    =>  'VisitsSummary.getVisits',
101
+						'idSite'    =>  $settings['matomo_siteid'],
102
+						'period'    =>  $period,
103
+						'date'      =>  'today',
104
+						'token_auth' =>  $settings['matomo_token'],
105
+						'format'    =>  'json'
106
+					]
107
+				]);
108 108
 
109
-                if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
110
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
111
-                    if ($result !== null) {
112
-                        return (int)$result;
113
-                    }
114
-                }
115
-            } catch (RequestException $ex) {
116
-            }
117
-        }
109
+				if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
110
+					$result = json_decode((string) $response->getBody(), true)['value'] ?? null;
111
+					if ($result !== null) {
112
+						return (int)$result;
113
+					}
114
+				}
115
+			} catch (RequestException $ex) {
116
+			}
117
+		}
118 118
 
119
-        return null;
120
-    }
119
+		return null;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
     public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
41 41
     {
42 42
         return Registry::cache()->file()->remember(
43
-            $module->name() . '-matomovisits-yearly-' . $block_id,
44
-            function () use ($module, $block_id): ?int {
43
+            $module->name().'-matomovisits-yearly-'.$block_id,
44
+            function() use ($module, $block_id) : ?int {
45 45
                 $visits_year = $this->visits($module, $block_id, 'year');
46 46
                 if ($visits_year === null) {
47 47
                     return null;
48 48
                 }
49
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
49
+                $visits_today = (int)$this->visits($module, $block_id, 'day');
50 50
 
51 51
                 return $visits_year - $visits_today;
52 52
             },
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
     public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
65 65
     {
66 66
         return Registry::cache()->array()->remember(
67
-            $module->name() . '-matomovisits-daily-' . $block_id,
68
-            function () use ($module, $block_id): ?int {
67
+            $module->name().'-matomovisits-daily-'.$block_id,
68
+            function() use ($module, $block_id) : ?int {
69 69
                 return $this->visits($module, $block_id, 'day');
70 70
             }
71 71
         );
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                 ]);
108 108
 
109 109
                 if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
110
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
110
+                    $result = json_decode((string)$response->getBody(), true)['value'] ?? null;
111 111
                     if ($result !== null) {
112 112
                         return (int)$result;
113 113
                     }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/CertificatesModule.php 2 patches
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -43,154 +43,154 @@
 block discarded – undo
43 43
  * Certificates Module.
44 44
  */
45 45
 class CertificatesModule extends AbstractModule implements
46
-    ModuleMyArtJaubInterface,
47
-    ModuleConfigInterface,
48
-    ModuleGlobalInterface,
49
-    ModuleListInterface
46
+	ModuleMyArtJaubInterface,
47
+	ModuleConfigInterface,
48
+	ModuleGlobalInterface,
49
+	ModuleListInterface
50 50
 {
51
-    use ModuleMyArtJaubTrait {
52
-        boot as traitBoot;
53
-    }
54
-    use ModuleConfigTrait;
55
-    use ModuleGlobalTrait;
56
-    use ModuleListTrait;
57
-
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
61
-     */
62
-    public function title(): string
63
-    {
64
-        return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
65
-    }
66
-
67
-    /**
68
-     * {@inheritDoc}
69
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
70
-     */
71
-    public function description(): string
72
-    {
73
-        //phpcs:ignore Generic.Files.LineLength.TooLong
74
-        return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
75
-    }
76
-
77
-    /**
78
-     * {@inheritDoc}
79
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
80
-     */
81
-    public function boot(): void
82
-    {
83
-        $this->traitBoot();
84
-        Registry::elementFactory()->register([
85
-            'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate')),
86
-            'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate')),
87
-            'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
88
-            'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
89
-            'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
90
-            'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
91
-            'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
92
-            'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'))
93
-        ]);
94
-    }
95
-
96
-    /**
97
-     * {@inheritDoc}
98
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
99
-     */
100
-    public function loadRoutes($router): void
101
-    {
102
-        $router->attach('', '', static function (Map $router): void {
103
-
104
-            $router->attach('', '/module-maj/certificates', static function (Map $router): void {
105
-
106
-                $router->attach('', '/admin', static function (Map $router): void {
107
-
108
-                    $router->get(AdminTreesPage::class, '/trees', AdminTreesPage::class)
109
-                        ->extras(['middleware' => [ AuthAdministrator::class ]]);
110
-
111
-                    $router->attach('', '/config/{tree}', static function (Map $router): void {
112
-
113
-                        $router->extras([
114
-                            'middleware' => [
115
-                                AuthManager::class,
116
-                            ],
117
-                        ]);
118
-                        $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
119
-                        $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
120
-                    });
121
-                });
122
-
123
-                $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
124
-                    ->extras([
125
-                        'middleware'            =>  [AuthTreePreference::class],
126
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
127
-                    ]);
128
-
129
-                $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
130
-
131
-                    $router->extras([
132
-                        'middleware'            =>  [AuthTreePreference::class],
133
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
134
-                    ]);
135
-
136
-                    $router->get(CertificatePage::class, '', CertificatePage::class);
137
-                    $router->get(CertificateImage::class, '/image', CertificateImage::class);
138
-                });
139
-            });
140
-        });
141
-    }
142
-
143
-    /**
144
-     * {@inheritDoc}
145
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
146
-     */
147
-    public function customModuleVersion(): string
148
-    {
149
-        return '2.1.0-v.1';
150
-    }
151
-
152
-    /**
153
-     * {@inheritDoc}
154
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
155
-     */
156
-    public function getConfigLink(): string
157
-    {
158
-        return route(AdminTreesPage::class);
159
-    }
160
-
161
-    /**
162
-     * {@inheritDoc}
163
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
164
-     */
165
-    public function headContent(): string
166
-    {
167
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
168
-    }
169
-
170
-    /**
171
-     * {@inheritDoc}
172
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
173
-     */
174
-    public function listUrl(Tree $tree, array $parameters = []): string
175
-    {
176
-        return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
177
-    }
178
-
179
-    /**
180
-     * {@inheritDoc}
181
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
182
-     */
183
-    public function listMenuClass(): string
184
-    {
185
-        return 'menu-maj-certificates';
186
-    }
187
-
188
-    /**
189
-     * {@inheritDoc}
190
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
191
-     */
192
-    public function listIsEmpty(Tree $tree): bool
193
-    {
194
-        return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
195
-    }
51
+	use ModuleMyArtJaubTrait {
52
+		boot as traitBoot;
53
+	}
54
+	use ModuleConfigTrait;
55
+	use ModuleGlobalTrait;
56
+	use ModuleListTrait;
57
+
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
61
+	 */
62
+	public function title(): string
63
+	{
64
+		return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
65
+	}
66
+
67
+	/**
68
+	 * {@inheritDoc}
69
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
70
+	 */
71
+	public function description(): string
72
+	{
73
+		//phpcs:ignore Generic.Files.LineLength.TooLong
74
+		return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
75
+	}
76
+
77
+	/**
78
+	 * {@inheritDoc}
79
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
80
+	 */
81
+	public function boot(): void
82
+	{
83
+		$this->traitBoot();
84
+		Registry::elementFactory()->register([
85
+			'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate')),
86
+			'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate')),
87
+			'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
88
+			'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
89
+			'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
90
+			'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
91
+			'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
92
+			'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'))
93
+		]);
94
+	}
95
+
96
+	/**
97
+	 * {@inheritDoc}
98
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
99
+	 */
100
+	public function loadRoutes($router): void
101
+	{
102
+		$router->attach('', '', static function (Map $router): void {
103
+
104
+			$router->attach('', '/module-maj/certificates', static function (Map $router): void {
105
+
106
+				$router->attach('', '/admin', static function (Map $router): void {
107
+
108
+					$router->get(AdminTreesPage::class, '/trees', AdminTreesPage::class)
109
+						->extras(['middleware' => [ AuthAdministrator::class ]]);
110
+
111
+					$router->attach('', '/config/{tree}', static function (Map $router): void {
112
+
113
+						$router->extras([
114
+							'middleware' => [
115
+								AuthManager::class,
116
+							],
117
+						]);
118
+						$router->get(AdminConfigPage::class, '', AdminConfigPage::class);
119
+						$router->post(AdminConfigAction::class, '', AdminConfigAction::class);
120
+					});
121
+				});
122
+
123
+				$router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
124
+					->extras([
125
+						'middleware'            =>  [AuthTreePreference::class],
126
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
127
+					]);
128
+
129
+				$router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
130
+
131
+					$router->extras([
132
+						'middleware'            =>  [AuthTreePreference::class],
133
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
134
+					]);
135
+
136
+					$router->get(CertificatePage::class, '', CertificatePage::class);
137
+					$router->get(CertificateImage::class, '/image', CertificateImage::class);
138
+				});
139
+			});
140
+		});
141
+	}
142
+
143
+	/**
144
+	 * {@inheritDoc}
145
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
146
+	 */
147
+	public function customModuleVersion(): string
148
+	{
149
+		return '2.1.0-v.1';
150
+	}
151
+
152
+	/**
153
+	 * {@inheritDoc}
154
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
155
+	 */
156
+	public function getConfigLink(): string
157
+	{
158
+		return route(AdminTreesPage::class);
159
+	}
160
+
161
+	/**
162
+	 * {@inheritDoc}
163
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
164
+	 */
165
+	public function headContent(): string
166
+	{
167
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
168
+	}
169
+
170
+	/**
171
+	 * {@inheritDoc}
172
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
173
+	 */
174
+	public function listUrl(Tree $tree, array $parameters = []): string
175
+	{
176
+		return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
177
+	}
178
+
179
+	/**
180
+	 * {@inheritDoc}
181
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
182
+	 */
183
+	public function listMenuClass(): string
184
+	{
185
+		return 'menu-maj-certificates';
186
+	}
187
+
188
+	/**
189
+	 * {@inheritDoc}
190
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
191
+	 */
192
+	public function listIsEmpty(Tree $tree): bool
193
+	{
194
+		return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function loadRoutes($router): void
101 101
     {
102
-        $router->attach('', '', static function (Map $router): void {
102
+        $router->attach('', '', static function(Map $router): void {
103 103
 
104
-            $router->attach('', '/module-maj/certificates', static function (Map $router): void {
104
+            $router->attach('', '/module-maj/certificates', static function(Map $router): void {
105 105
 
106
-                $router->attach('', '/admin', static function (Map $router): void {
106
+                $router->attach('', '/admin', static function(Map $router): void {
107 107
 
108 108
                     $router->get(AdminTreesPage::class, '/trees', AdminTreesPage::class)
109
-                        ->extras(['middleware' => [ AuthAdministrator::class ]]);
109
+                        ->extras(['middleware' => [AuthAdministrator::class]]);
110 110
 
111
-                    $router->attach('', '/config/{tree}', static function (Map $router): void {
111
+                    $router->attach('', '/config/{tree}', static function(Map $router): void {
112 112
 
113 113
                         $router->extras([
114 114
                             'middleware' => [
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                         'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
127 127
                     ]);
128 128
 
129
-                $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
129
+                $router->attach('', '/certificate/{tree}/{cid}', static function(Map $router): void {
130 130
 
131 131
                     $router->extras([
132 132
                         'middleware'            =>  [AuthTreePreference::class],
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public function headContent(): string
166 166
     {
167
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
167
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
168 168
     }
169 169
 
170 170
     /**
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      */
174 174
     public function listUrl(Tree $tree, array $parameters = []): string
175 175
     {
176
-        return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
176
+        return route(CertificatesList::class, ['tree' => $tree->name()] + $parameters);
177 177
     }
178 178
 
179 179
     /**
@@ -191,6 +191,6 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function listIsEmpty(Tree $tree): bool
193 193
     {
194
-        return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
194
+        return Auth::accessLevel($tree) > (int)$tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string)Auth::PRIV_HIDE);
195 195
     }
196 196
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Model/Certificate.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -25,212 +25,212 @@
 block discarded – undo
25 25
  */
26 26
 class Certificate
27 27
 {
28
-    /**
29
-     * Pattern to extract information from a file name.
30
-     * Specific to the author's workflow.
31
-     * @var string
32
-     */
33
-    private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong
34
-
35
-    /**
36
-     * @var Tree $tree
37
-     */
38
-    private $tree;
39
-
40
-    /**
41
-     * @var string $path
42
-     * */
43
-    private $path;
44
-
45
-    /**
46
-     * @var string|null $city
47
-     * $city */
48
-    private $city;
49
-
50
-    /**
51
-     * @var string|null $filename
52
-     */
53
-    private $filename;
54
-
55
-    /**
56
-     * @var string|null $extension
57
-     */
58
-    private $extension;
59
-
60
-    /**
61
-     * @var string|null $type
62
-     */
63
-    private $type;
64
-
65
-    /**
66
-     * @var string|null $description
67
-     */
68
-    private $description;
69
-
70
-    /**
71
-     * @var Date|null $date
72
-     */
73
-    private $date;
74
-
75
-    /**
76
-     * Contructor for Certificate
77
-     *
78
-     * @param Tree $tree
79
-     * @param string $path
80
-     */
81
-    public function __construct(Tree $tree, string $path)
82
-    {
83
-        $this->tree = $tree;
84
-        $this->path = $path;
85
-        $this->extractDataFromPath($path);
86
-    }
87
-
88
-    /**
89
-     * Populate fields from the filename, based on a predeterminate pattern.
90
-     * Logic specific to the author.
91
-     *
92
-     * @param string $path
93
-     */
94
-    protected function extractDataFromPath(string $path): void
95
-    {
96
-        $path_parts = pathinfo($path);
97
-        $this->city = $path_parts['dirname'];
98
-        $this->filename = $path_parts['filename'];
99
-        $this->extension = $path_parts['extension'] ?? '';
100
-
101
-        if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) {
102
-            $this->type = $match['type'];
103
-            $this->description = $match['descr'];
104
-
105
-            $day = $match['day'] ?? '';
106
-            $month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
107
-            $month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
108
-            $year = $match['year'] ?? '';
109
-
110
-            $this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
111
-        } else {
112
-            $this->description = $this->filename;
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Get the family tree of the certificate
118
-     *
119
-     * @return Tree
120
-     */
121
-    public function tree(): Tree
122
-    {
123
-        return $this->tree;
124
-    }
125
-
126
-    /**
127
-     * Get the path of the certificate in the file system.
128
-     *
129
-     * @return string
130
-     */
131
-    public function path(): string
132
-    {
133
-        return $this->path;
134
-    }
135
-
136
-    /**
137
-     * The the path of the certificate, in a Gedcom canonical form.
138
-     *
139
-     * @return string
140
-     */
141
-    public function gedcomPath(): string
142
-    {
143
-        return str_replace('\\', '/', $this->path);
144
-    }
145
-
146
-    /**
147
-     * Get the certificate name.
148
-     *
149
-     * @return string
150
-     */
151
-    public function name(): string
152
-    {
153
-        return $this->filename ?? '';
154
-    }
155
-
156
-    /**
157
-     * Get the certificate's city (the first level folder).
158
-     *
159
-     * @return string
160
-     */
161
-    public function city(): string
162
-    {
163
-        return $this->city ?? '';
164
-    }
165
-
166
-    /**
167
-     * Get the certificate's date. Extracted from the file name.
168
-     *
169
-     * @return Date
170
-     */
171
-    public function date(): Date
172
-    {
173
-        return $this->date ?? new Date('');
174
-    }
175
-
176
-    /**
177
-     * Get the certificate's type. Extracted from the file name.
178
-     *
179
-     * @return string
180
-     */
181
-    public function type(): string
182
-    {
183
-        return $this->type ?? '';
184
-    }
185
-
186
-    /**
187
-     * Get the certificate's description.  Extracted from the file name.
188
-     * @return string
189
-     */
190
-    public function description(): string
191
-    {
192
-        return $this->description ?? '';
193
-    }
194
-
195
-    /**
196
-     * Get the certificate's description to be used for sorting.
197
-     * This is based on surnames (at least 3 letters) found in the file name.
198
-     *
199
-     * @return string
200
-     */
201
-    public function sortDescription(): string
202
-    {
203
-        $sort_prefix = '';
204
-        if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
205
-            $sort_prefix = implode('_', array_map(function ($match) {
206
-                return $match[1];
207
-            }, $matches)) . '_';
208
-        }
209
-        return $sort_prefix . $this->description();
210
-    }
211
-
212
-    /**
213
-     * Get the certificate's MIME type.
214
-     *
215
-     * @return string
216
-     */
217
-    public function mimeType(): string
218
-    {
219
-        return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
220
-    }
221
-
222
-    /**
223
-     * Get the base parameters to be used in url referencing the certificate.
224
-     *
225
-     * @param UrlObfuscatorService $url_obfuscator_service
226
-     * @return array
227
-     */
228
-    public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
229
-    {
230
-        $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
231
-        return [
232
-            'tree' => $this->tree->name(),
233
-            'cid' => $url_obfuscator_service->obfuscate($this->path)
234
-        ];
235
-    }
28
+	/**
29
+	 * Pattern to extract information from a file name.
30
+	 * Specific to the author's workflow.
31
+	 * @var string
32
+	 */
33
+	private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong
34
+
35
+	/**
36
+	 * @var Tree $tree
37
+	 */
38
+	private $tree;
39
+
40
+	/**
41
+	 * @var string $path
42
+	 * */
43
+	private $path;
44
+
45
+	/**
46
+	 * @var string|null $city
47
+	 * $city */
48
+	private $city;
49
+
50
+	/**
51
+	 * @var string|null $filename
52
+	 */
53
+	private $filename;
54
+
55
+	/**
56
+	 * @var string|null $extension
57
+	 */
58
+	private $extension;
59
+
60
+	/**
61
+	 * @var string|null $type
62
+	 */
63
+	private $type;
64
+
65
+	/**
66
+	 * @var string|null $description
67
+	 */
68
+	private $description;
69
+
70
+	/**
71
+	 * @var Date|null $date
72
+	 */
73
+	private $date;
74
+
75
+	/**
76
+	 * Contructor for Certificate
77
+	 *
78
+	 * @param Tree $tree
79
+	 * @param string $path
80
+	 */
81
+	public function __construct(Tree $tree, string $path)
82
+	{
83
+		$this->tree = $tree;
84
+		$this->path = $path;
85
+		$this->extractDataFromPath($path);
86
+	}
87
+
88
+	/**
89
+	 * Populate fields from the filename, based on a predeterminate pattern.
90
+	 * Logic specific to the author.
91
+	 *
92
+	 * @param string $path
93
+	 */
94
+	protected function extractDataFromPath(string $path): void
95
+	{
96
+		$path_parts = pathinfo($path);
97
+		$this->city = $path_parts['dirname'];
98
+		$this->filename = $path_parts['filename'];
99
+		$this->extension = $path_parts['extension'] ?? '';
100
+
101
+		if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) {
102
+			$this->type = $match['type'];
103
+			$this->description = $match['descr'];
104
+
105
+			$day = $match['day'] ?? '';
106
+			$month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
107
+			$month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
108
+			$year = $match['year'] ?? '';
109
+
110
+			$this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
111
+		} else {
112
+			$this->description = $this->filename;
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * Get the family tree of the certificate
118
+	 *
119
+	 * @return Tree
120
+	 */
121
+	public function tree(): Tree
122
+	{
123
+		return $this->tree;
124
+	}
125
+
126
+	/**
127
+	 * Get the path of the certificate in the file system.
128
+	 *
129
+	 * @return string
130
+	 */
131
+	public function path(): string
132
+	{
133
+		return $this->path;
134
+	}
135
+
136
+	/**
137
+	 * The the path of the certificate, in a Gedcom canonical form.
138
+	 *
139
+	 * @return string
140
+	 */
141
+	public function gedcomPath(): string
142
+	{
143
+		return str_replace('\\', '/', $this->path);
144
+	}
145
+
146
+	/**
147
+	 * Get the certificate name.
148
+	 *
149
+	 * @return string
150
+	 */
151
+	public function name(): string
152
+	{
153
+		return $this->filename ?? '';
154
+	}
155
+
156
+	/**
157
+	 * Get the certificate's city (the first level folder).
158
+	 *
159
+	 * @return string
160
+	 */
161
+	public function city(): string
162
+	{
163
+		return $this->city ?? '';
164
+	}
165
+
166
+	/**
167
+	 * Get the certificate's date. Extracted from the file name.
168
+	 *
169
+	 * @return Date
170
+	 */
171
+	public function date(): Date
172
+	{
173
+		return $this->date ?? new Date('');
174
+	}
175
+
176
+	/**
177
+	 * Get the certificate's type. Extracted from the file name.
178
+	 *
179
+	 * @return string
180
+	 */
181
+	public function type(): string
182
+	{
183
+		return $this->type ?? '';
184
+	}
185
+
186
+	/**
187
+	 * Get the certificate's description.  Extracted from the file name.
188
+	 * @return string
189
+	 */
190
+	public function description(): string
191
+	{
192
+		return $this->description ?? '';
193
+	}
194
+
195
+	/**
196
+	 * Get the certificate's description to be used for sorting.
197
+	 * This is based on surnames (at least 3 letters) found in the file name.
198
+	 *
199
+	 * @return string
200
+	 */
201
+	public function sortDescription(): string
202
+	{
203
+		$sort_prefix = '';
204
+		if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
205
+			$sort_prefix = implode('_', array_map(function ($match) {
206
+				return $match[1];
207
+			}, $matches)) . '_';
208
+		}
209
+		return $sort_prefix . $this->description();
210
+	}
211
+
212
+	/**
213
+	 * Get the certificate's MIME type.
214
+	 *
215
+	 * @return string
216
+	 */
217
+	public function mimeType(): string
218
+	{
219
+		return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
220
+	}
221
+
222
+	/**
223
+	 * Get the base parameters to be used in url referencing the certificate.
224
+	 *
225
+	 * @param UrlObfuscatorService $url_obfuscator_service
226
+	 * @return array
227
+	 */
228
+	public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
229
+	{
230
+		$url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
231
+		return [
232
+			'tree' => $this->tree->name(),
233
+			'cid' => $url_obfuscator_service->obfuscate($this->path)
234
+		];
235
+	}
236 236
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -202,11 +202,11 @@
 block discarded – undo
202 202
     {
203 203
         $sort_prefix = '';
204 204
         if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
205
-            $sort_prefix = implode('_', array_map(function ($match) {
205
+            $sort_prefix = implode('_', array_map(function($match) {
206 206
                 return $match[1];
207
-            }, $matches)) . '_';
207
+            }, $matches)).'_';
208 208
         }
209
-        return $sort_prefix . $this->description();
209
+        return $sort_prefix.$this->description();
210 210
     }
211 211
 
212 212
     /**
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Model/Watermark.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -19,112 +19,112 @@
 block discarded – undo
19 19
  */
20 20
 class Watermark
21 21
 {
22
-    /**
23
-     * Default font color for watermarks
24
-     * @var string DEFAULT_COLOR
25
-     * */
26
-    public const DEFAULT_COLOR = '#4D6DF3';
27
-
28
-    /**
29
-     * Default maximum font size for watermarks
30
-     * @var string DEFAULT_SIZE
31
-     * */
32
-    public const DEFAULT_SIZE = 18;
33
-
34
-    /**
35
-     * @var string $text
36
-     */
37
-    private $text;
38
-
39
-    /**
40
-     * @var string $color;
41
-     */
42
-    private $color;
43
-
44
-
45
-    /**
46
-     * @var int $size
47
-     */
48
-    private $size;
49
-
50
-    /**
51
-     * Constructor for Watermark data class
52
-     *
53
-     * @param string $text
54
-     * @param string $color
55
-     * @param int $size
56
-     */
57
-    public function __construct(string $text, string $color, int $size)
58
-    {
59
-        $this->text = $text;
60
-        $this->color = $color;
61
-        $this->size = $size;
62
-    }
63
-
64
-    /**
65
-     * Get the watermark text.
66
-     *
67
-     * @return string
68
-     */
69
-    public function text(): string
70
-    {
71
-        return $this->text;
72
-    }
73
-
74
-    /**
75
-     * Get the watermark font color.
76
-     *
77
-     * @return string
78
-     */
79
-    public function color(): string
80
-    {
81
-        return $this->color;
82
-    }
83
-
84
-    /**
85
-     * Get the watermark maximum font size.
86
-     * @return int
87
-     */
88
-    public function size(): int
89
-    {
90
-        return $this->size;
91
-    }
92
-
93
-    /**
94
-     * Return an estimate of the size in pixels of the watermark text length.
95
-     *
96
-     * @return int
97
-     */
98
-    public function textLengthEstimate(): int
99
-    {
100
-        return $this->stringLengthEstimate(mb_strlen($this->text), $this->size);
101
-    }
102
-
103
-    /**
104
-     * Decrease the font size if necessary, based on the image width.
105
-     *
106
-     * @param int $width
107
-     */
108
-    public function adjustSize(int $width): void
109
-    {
110
-        $len = mb_strlen($this->text);
111
-        while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) {
112
-            $this->size--;
113
-            if ($this->size == 2) {
114
-                return;
115
-            }
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Return an estimate of the size in pixels of a text in a specified font size.
121
-     *
122
-     * @param int $text_length
123
-     * @param int $font_size
124
-     * @return int
125
-     */
126
-    private function stringLengthEstimate(int $text_length, int $font_size): int
127
-    {
128
-        return $text_length * (int) ceil(($font_size + 2) * 0.5);
129
-    }
22
+	/**
23
+	 * Default font color for watermarks
24
+	 * @var string DEFAULT_COLOR
25
+	 * */
26
+	public const DEFAULT_COLOR = '#4D6DF3';
27
+
28
+	/**
29
+	 * Default maximum font size for watermarks
30
+	 * @var string DEFAULT_SIZE
31
+	 * */
32
+	public const DEFAULT_SIZE = 18;
33
+
34
+	/**
35
+	 * @var string $text
36
+	 */
37
+	private $text;
38
+
39
+	/**
40
+	 * @var string $color;
41
+	 */
42
+	private $color;
43
+
44
+
45
+	/**
46
+	 * @var int $size
47
+	 */
48
+	private $size;
49
+
50
+	/**
51
+	 * Constructor for Watermark data class
52
+	 *
53
+	 * @param string $text
54
+	 * @param string $color
55
+	 * @param int $size
56
+	 */
57
+	public function __construct(string $text, string $color, int $size)
58
+	{
59
+		$this->text = $text;
60
+		$this->color = $color;
61
+		$this->size = $size;
62
+	}
63
+
64
+	/**
65
+	 * Get the watermark text.
66
+	 *
67
+	 * @return string
68
+	 */
69
+	public function text(): string
70
+	{
71
+		return $this->text;
72
+	}
73
+
74
+	/**
75
+	 * Get the watermark font color.
76
+	 *
77
+	 * @return string
78
+	 */
79
+	public function color(): string
80
+	{
81
+		return $this->color;
82
+	}
83
+
84
+	/**
85
+	 * Get the watermark maximum font size.
86
+	 * @return int
87
+	 */
88
+	public function size(): int
89
+	{
90
+		return $this->size;
91
+	}
92
+
93
+	/**
94
+	 * Return an estimate of the size in pixels of the watermark text length.
95
+	 *
96
+	 * @return int
97
+	 */
98
+	public function textLengthEstimate(): int
99
+	{
100
+		return $this->stringLengthEstimate(mb_strlen($this->text), $this->size);
101
+	}
102
+
103
+	/**
104
+	 * Decrease the font size if necessary, based on the image width.
105
+	 *
106
+	 * @param int $width
107
+	 */
108
+	public function adjustSize(int $width): void
109
+	{
110
+		$len = mb_strlen($this->text);
111
+		while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) {
112
+			$this->size--;
113
+			if ($this->size == 2) {
114
+				return;
115
+			}
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Return an estimate of the size in pixels of a text in a specified font size.
121
+	 *
122
+	 * @param int $text_length
123
+	 * @param int $font_size
124
+	 * @return int
125
+	 */
126
+	private function stringLengthEstimate(int $text_length, int $font_size): int
127
+	{
128
+		return $text_length * (int) ceil(($font_size + 2) * 0.5);
129
+	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -125,6 +125,6 @@
 block discarded – undo
125 125
      */
126 126
     private function stringLengthEstimate(int $text_length, int $font_size): int
127 127
     {
128
-        return $text_length * (int) ceil(($font_size + 2) * 0.5);
128
+        return $text_length * (int)ceil(($font_size + 2) * 0.5);
129 129
     }
130 130
 }
Please login to merge, or discard this patch.