Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Module/PatronymicLineage/Http/RequestHandlers/SurnamesList.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -30,74 +30,74 @@
 block discarded – undo
30 30
  */
31 31
 class SurnamesList implements RequestHandlerInterface
32 32
 {
33
-    use ViewResponseTrait;
34
-
35
-    /**
36
-     * @var PatronymicLineageModule|null $module
37
-     */
38
-    private $module;
39
-
40
-    /**
41
-     * @var IndividualListModule|null $indilist_module
42
-     */
43
-    private $indilist_module;
44
-
45
-    /**
46
-     * Constructor for SurnamesList Request Handler
47
-     *
48
-     * @param ModuleService $module_service
49
-     */
50
-    public function __construct(ModuleService $module_service)
51
-    {
52
-        $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
53
-        $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
54
-    }
55
-
56
-    /**
57
-     * {@inheritDoc}
58
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
-     */
60
-    public function handle(ServerRequestInterface $request): ResponseInterface
61
-    {
62
-        if ($this->module === null) {
63
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
-        }
65
-
66
-        if ($this->indilist_module === null) {
67
-            throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
68
-        }
69
-
70
-        $tree = $request->getAttribute('tree');
71
-        assert($tree instanceof Tree);
72
-
73
-        $initial = $request->getAttribute('alpha');
74
-        $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
-            ->reject(function (int $count, string $initial): bool {
76
-
77
-                return $initial === '@' || $initial === ',';
78
-            });
79
-
80
-        $show_all = $request->getQueryParams()['show_all'] ?? 'no';
81
-
82
-        if ($show_all === 'yes') {
83
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
84
-            $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85
-        } elseif ($initial !== null && mb_strlen($initial) == 1) {
86
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
87
-            $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88
-        } else {
89
-            $title =  I18N::translate('Patronymic Lineages');
90
-            $surnames = [];
91
-        }
92
-
93
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
94
-            'title'         =>  $title,
95
-            'module'        =>  $this->module,
96
-            'tree'          =>  $tree,
97
-            'initials_list' =>  $initials_list,
98
-            'initial'       =>  $initial,
99
-            'show_all'      =>  $show_all,
100
-            'surnames'      =>  $surnames
101
-        ]);
102
-    }
33
+	use ViewResponseTrait;
34
+
35
+	/**
36
+	 * @var PatronymicLineageModule|null $module
37
+	 */
38
+	private $module;
39
+
40
+	/**
41
+	 * @var IndividualListModule|null $indilist_module
42
+	 */
43
+	private $indilist_module;
44
+
45
+	/**
46
+	 * Constructor for SurnamesList Request Handler
47
+	 *
48
+	 * @param ModuleService $module_service
49
+	 */
50
+	public function __construct(ModuleService $module_service)
51
+	{
52
+		$this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first();
53
+		$this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first();
54
+	}
55
+
56
+	/**
57
+	 * {@inheritDoc}
58
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
+	 */
60
+	public function handle(ServerRequestInterface $request): ResponseInterface
61
+	{
62
+		if ($this->module === null) {
63
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
+		}
65
+
66
+		if ($this->indilist_module === null) {
67
+			throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.'));
68
+		}
69
+
70
+		$tree = $request->getAttribute('tree');
71
+		assert($tree instanceof Tree);
72
+
73
+		$initial = $request->getAttribute('alpha');
74
+		$initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
+			->reject(function (int $count, string $initial): bool {
76
+
77
+				return $initial === '@' || $initial === ',';
78
+			});
79
+
80
+		$show_all = $request->getQueryParams()['show_all'] ?? 'no';
81
+
82
+		if ($show_all === 'yes') {
83
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
84
+			$surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85
+		} elseif ($initial !== null && mb_strlen($initial) == 1) {
86
+			$title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
87
+			$surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88
+		} else {
89
+			$title =  I18N::translate('Patronymic Lineages');
90
+			$surnames = [];
91
+		}
92
+
93
+		return $this->viewResponse($this->module->name() . '::surnames-page', [
94
+			'title'         =>  $title,
95
+			'module'        =>  $this->module,
96
+			'tree'          =>  $tree,
97
+			'initials_list' =>  $initials_list,
98
+			'initial'       =>  $initial,
99
+			'show_all'      =>  $show_all,
100
+			'surnames'      =>  $surnames
101
+		]);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
         $initial = $request->getAttribute('alpha');
74 74
         $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale()))
75
-            ->reject(function (int $count, string $initial): bool {
75
+            ->reject(function(int $count, string $initial): bool {
76 76
 
77 77
                 return $initial === '@' || $initial === ',';
78 78
             });
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
         $show_all = $request->getQueryParams()['show_all'] ?? 'no';
81 81
 
82 82
         if ($show_all === 'yes') {
83
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All');
83
+            $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All');
84 84
             $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale());
85 85
         } elseif ($initial !== null && mb_strlen($initial) == 1) {
86
-            $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial;
86
+            $title = I18N::translate('Patronymic Lineages').' — '.$initial;
87 87
             $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale());
88 88
         } else {
89
-            $title =  I18N::translate('Patronymic Lineages');
89
+            $title = I18N::translate('Patronymic Lineages');
90 90
             $surnames = [];
91 91
         }
92 92
 
93
-        return $this->viewResponse($this->module->name() . '::surnames-page', [
93
+        return $this->viewResponse($this->module->name().'::surnames-page', [
94 94
             'title'         =>  $title,
95 95
             'module'        =>  $this->module,
96 96
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/IsSourced/Services/SourceStatusService.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -30,127 +30,127 @@
 block discarded – undo
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 array $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
-            assert($source_status instanceof FactSourceStatus);
115
-            if ($source_status->isFullySourced()) {
116
-                return $source_status;
117
-            }
118
-        }
119
-
120
-        return $source_status;
121
-    }
122
-
123
-    /**
124
-     * Return the status of source citations for an individual's birth events.
125
-     *
126
-     * @param Individual $individual
127
-     * @return FactSourceStatus
128
-     */
129
-    public function sourceStatusForBirth(Individual $individual): FactSourceStatus
130
-    {
131
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
132
-    }
133
-
134
-    /**
135
-     * Return the status of source citations for an individual's death events.
136
-     *
137
-     * @param Individual $individual
138
-     * @return FactSourceStatus
139
-     */
140
-    public function sourceStatusForDeath(Individual $individual): FactSourceStatus
141
-    {
142
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
143
-    }
144
-
145
-    /**
146
-     * Return the status of source citations for a family's marriage events.
147
-     *
148
-     * @param Family $family
149
-     * @return FactSourceStatus
150
-     */
151
-    public function sourceStatusForMarriage(Family $family): FactSourceStatus
152
-    {
153
-        $marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']);
154
-        return $this->sourceStatusForFactsWithTags($family, $marr_events);
155
-    }
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 array $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
+			assert($source_status instanceof FactSourceStatus);
115
+			if ($source_status->isFullySourced()) {
116
+				return $source_status;
117
+			}
118
+		}
119
+
120
+		return $source_status;
121
+	}
122
+
123
+	/**
124
+	 * Return the status of source citations for an individual's birth events.
125
+	 *
126
+	 * @param Individual $individual
127
+	 * @return FactSourceStatus
128
+	 */
129
+	public function sourceStatusForBirth(Individual $individual): FactSourceStatus
130
+	{
131
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
132
+	}
133
+
134
+	/**
135
+	 * Return the status of source citations for an individual's death events.
136
+	 *
137
+	 * @param Individual $individual
138
+	 * @return FactSourceStatus
139
+	 */
140
+	public function sourceStatusForDeath(Individual $individual): FactSourceStatus
141
+	{
142
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
143
+	}
144
+
145
+	/**
146
+	 * Return the status of source citations for a family's marriage events.
147
+	 *
148
+	 * @param Family $family
149
+	 * @return FactSourceStatus
150
+	 */
151
+	public function sourceStatusForMarriage(Family $family): FactSourceStatus
152
+	{
153
+		$marr_events = array_merge(Gedcom::MARRIAGE_EVENTS, ['MARC', 'MARL', 'MARS']);
154
+		return $this->sourceStatusForFactsWithTags($family, $marr_events);
155
+	}
156 156
 }
Please login to merge, or discard this patch.
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/WelcomeBlockModule.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,159 +33,159 @@
 block discarded – undo
33 33
  */
34 34
 class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface
35 35
 {
36
-    use ModuleMyArtJaubTrait;
37
-    use ModuleBlockTrait;
38
-
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
-     */
43
-    public function title(): string
44
-    {
45
-        return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
46
-    }
47
-
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
-     */
52
-    public function description(): string
53
-    {
54
-        //phpcs:ignore Generic.Files.LineLength.TooLong
55
-        return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
56
-    }
57
-
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
61
-     */
62
-    public function loadRoutes(Map $router): void
63
-    {
64
-        $router->attach('', '', static function (Map $router): void {
65
-
66
-            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
67
-
68
-                $router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
69
-            });
70
-        });
71
-    }
72
-
73
-    /**
74
-     * {@inheritDoc}
75
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
76
-     */
77
-    public function customModuleVersion(): string
78
-    {
79
-        return '2.0.11-v.2';
80
-    }
81
-
82
-    /**
83
-     * {@inheritDoc}
84
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
85
-     */
86
-    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
87
-    {
88
-        $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
89
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
90
-
91
-        $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
92
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
93
-
94
-        $content = view($this->name() . '::block-embed', [
95
-            'block_id'                  =>  $block_id,
96
-            'fab_welcome_block_view'    =>  $fab_welcome_block_view,
97
-            'fab_login_block_view'      =>  $fab_login_block_view,
98
-            'matomo_enabled'            =>  $this->isMatomoEnabled($block_id),
99
-            'js_script_url'             =>  $this->assetUrl('js/welcomeblock.min.js')
100
-        ]);
101
-
102
-        if ($context !== self::CONTEXT_EMBED) {
103
-            return view('modules/block-template', [
104
-                'block'      => Str::kebab($this->name()),
105
-                'id'         => $block_id,
106
-                'config_url' => $this->configUrl($tree, $context, $block_id),
107
-                'title'      => $tree->title(),
108
-                'content'    => $content,
109
-            ]);
110
-        }
111
-
112
-        return $content;
113
-    }
114
-
115
-    /**
116
-     * {@inheritDoc}
117
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
118
-     */
119
-    public function isTreeBlock(): bool
120
-    {
121
-        return true;
122
-    }
123
-
124
-    /**
125
-     * {@inheritDoc}
126
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
127
-     */
128
-    public function editBlockConfiguration(Tree $tree, int $block_id): string
129
-    {
130
-        return view($this->name() . '::config', $this->matomoSettings($block_id));
131
-    }
132
-
133
-    /**
134
-     * {@inheritDoc}
135
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
136
-     */
137
-    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
138
-    {
139
-        $params = (array) $request->getParsedBody();
140
-
141
-        $matomo_enabled = $params['matomo_enabled'] == 'yes';
142
-        $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
143
-        if (!$matomo_enabled) {
144
-            return;
145
-        }
146
-
147
-        if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
148
-            FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
149
-            return;
150
-        }
151
-
152
-        if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
153
-            FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
154
-            return;
155
-        }
156
-
157
-        $this
158
-            ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
159
-            ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
160
-            ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
161
-
162
-        Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id);
163
-    }
164
-
165
-    /**
166
-     * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
167
-     *
168
-     * @param int $block_id
169
-     * @return bool
170
-     */
171
-    public function isMatomoEnabled(int $block_id): bool
172
-    {
173
-        return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
174
-    }
175
-
176
-    /**
177
-     * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
178
-     *
179
-     * @param int $block_id
180
-     * @return array<string, mixed>
181
-     */
182
-    public function matomoSettings(int $block_id): array
183
-    {
184
-        return [
185
-            'matomo_enabled' => $this->isMatomoEnabled($block_id),
186
-            'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
187
-            'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
188
-            'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
189
-        ];
190
-    }
36
+	use ModuleMyArtJaubTrait;
37
+	use ModuleBlockTrait;
38
+
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
+	 */
43
+	public function title(): string
44
+	{
45
+		return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
46
+	}
47
+
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
+	 */
52
+	public function description(): string
53
+	{
54
+		//phpcs:ignore Generic.Files.LineLength.TooLong
55
+		return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
56
+	}
57
+
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
61
+	 */
62
+	public function loadRoutes(Map $router): void
63
+	{
64
+		$router->attach('', '', static function (Map $router): void {
65
+
66
+			$router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
67
+
68
+				$router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
69
+			});
70
+		});
71
+	}
72
+
73
+	/**
74
+	 * {@inheritDoc}
75
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
76
+	 */
77
+	public function customModuleVersion(): string
78
+	{
79
+		return '2.0.11-v.2';
80
+	}
81
+
82
+	/**
83
+	 * {@inheritDoc}
84
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
85
+	 */
86
+	public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
87
+	{
88
+		$fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
89
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
90
+
91
+		$fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
92
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
93
+
94
+		$content = view($this->name() . '::block-embed', [
95
+			'block_id'                  =>  $block_id,
96
+			'fab_welcome_block_view'    =>  $fab_welcome_block_view,
97
+			'fab_login_block_view'      =>  $fab_login_block_view,
98
+			'matomo_enabled'            =>  $this->isMatomoEnabled($block_id),
99
+			'js_script_url'             =>  $this->assetUrl('js/welcomeblock.min.js')
100
+		]);
101
+
102
+		if ($context !== self::CONTEXT_EMBED) {
103
+			return view('modules/block-template', [
104
+				'block'      => Str::kebab($this->name()),
105
+				'id'         => $block_id,
106
+				'config_url' => $this->configUrl($tree, $context, $block_id),
107
+				'title'      => $tree->title(),
108
+				'content'    => $content,
109
+			]);
110
+		}
111
+
112
+		return $content;
113
+	}
114
+
115
+	/**
116
+	 * {@inheritDoc}
117
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
118
+	 */
119
+	public function isTreeBlock(): bool
120
+	{
121
+		return true;
122
+	}
123
+
124
+	/**
125
+	 * {@inheritDoc}
126
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
127
+	 */
128
+	public function editBlockConfiguration(Tree $tree, int $block_id): string
129
+	{
130
+		return view($this->name() . '::config', $this->matomoSettings($block_id));
131
+	}
132
+
133
+	/**
134
+	 * {@inheritDoc}
135
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
136
+	 */
137
+	public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
138
+	{
139
+		$params = (array) $request->getParsedBody();
140
+
141
+		$matomo_enabled = $params['matomo_enabled'] == 'yes';
142
+		$this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
143
+		if (!$matomo_enabled) {
144
+			return;
145
+		}
146
+
147
+		if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
148
+			FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
149
+			return;
150
+		}
151
+
152
+		if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
153
+			FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
154
+			return;
155
+		}
156
+
157
+		$this
158
+			->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
159
+			->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
160
+			->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
161
+
162
+		Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id);
163
+	}
164
+
165
+	/**
166
+	 * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
167
+	 *
168
+	 * @param int $block_id
169
+	 * @return bool
170
+	 */
171
+	public function isMatomoEnabled(int $block_id): bool
172
+	{
173
+		return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
174
+	}
175
+
176
+	/**
177
+	 * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
178
+	 *
179
+	 * @param int $block_id
180
+	 * @return array<string, mixed>
181
+	 */
182
+	public function matomoSettings(int $block_id): array
183
+	{
184
+		return [
185
+			'matomo_enabled' => $this->isMatomoEnabled($block_id),
186
+			'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
187
+			'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
188
+			'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
189
+		];
190
+	}
191 191
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function loadRoutes(Map $router): void
63 63
     {
64
-        $router->attach('', '', static function (Map $router): void {
64
+        $router->attach('', '', static function(Map $router): void {
65 65
 
66
-            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
66
+            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function(Map $router): void {
67 67
 
68 68
                 $router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
69 69
             });
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
92 92
             ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
93 93
 
94
-        $content = view($this->name() . '::block-embed', [
94
+        $content = view($this->name().'::block-embed', [
95 95
             'block_id'                  =>  $block_id,
96 96
             'fab_welcome_block_view'    =>  $fab_welcome_block_view,
97 97
             'fab_login_block_view'      =>  $fab_login_block_view,
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function editBlockConfiguration(Tree $tree, int $block_id): string
129 129
     {
130
-        return view($this->name() . '::config', $this->matomoSettings($block_id));
130
+        return view($this->name().'::config', $this->matomoSettings($block_id));
131 131
     }
132 132
 
133 133
     /**
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
138 138
     {
139
-        $params = (array) $request->getParsedBody();
139
+        $params = (array)$request->getParsedBody();
140 140
 
141 141
         $matomo_enabled = $params['matomo_enabled'] == 'yes';
142 142
         $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
160 160
             ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
161 161
 
162
-        Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id);
162
+        Registry::cache()->file()->forget($this->name().'-matomovisits-yearly-'.$block_id);
163 163
     }
164 164
 
165 165
     /**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
             'matomo_enabled' => $this->isMatomoEnabled($block_id),
186 186
             'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
187 187
             'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
188
-            'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
188
+            'matomo_siteid'  => (int)$this->getBlockSetting($block_id, 'matomo_siteid', '0')
189 189
         ];
190 190
     }
191 191
 }
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.