Passed
Push — feature/code-analysis ( e321b8...2d8a51 )
by Jonathan
13:14 queued 09:07
created
app/Contracts/GeoDispersion/GeoAnalysisInterface.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -22,26 +22,26 @@
 block discarded – undo
22 22
  */
23 23
 interface GeoAnalysisInterface
24 24
 {
25
-    /**
26
-     * Get the geographical dispersion analysis title
27
-     *
28
-     * @return string
29
-     */
30
-    public function title(): string;
25
+	/**
26
+	 * Get the geographical dispersion analysis title
27
+	 *
28
+	 * @return string
29
+	 */
30
+	public function title(): string;
31 31
 
32
-    /**
33
-     * Gets the function to translate
34
-     *
35
-     * @return callable(int $count): string
36
-     */
37
-    public function itemsDescription(): callable;
32
+	/**
33
+	 * Gets the function to translate
34
+	 *
35
+	 * @return callable(int $count): string
36
+	 */
37
+	public function itemsDescription(): callable;
38 38
 
39
-    /**
40
-     * Get the results of the geographical dispersion analysis
41
-     *
42
-     * @param Tree $tree
43
-     * @param int $depth
44
-     * @return GeoAnalysisResults
45
-     */
46
-    public function results(Tree $tree, int $depth): GeoAnalysisResults;
39
+	/**
40
+	 * Get the results of the geographical dispersion analysis
41
+	 *
42
+	 * @param Tree $tree
43
+	 * @param int $depth
44
+	 * @return GeoAnalysisResults
45
+	 */
46
+	public function results(Tree $tree, int $depth): GeoAnalysisResults;
47 47
 }
Please login to merge, or discard this patch.
app/Contracts/GeoDispersion/MapDefinitionInterface.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -19,24 +19,24 @@
 block discarded – undo
19 19
  */
20 20
 interface MapDefinitionInterface
21 21
 {
22
-    /**
23
-     * Get the map ID
24
-     *
25
-     * @return string
26
-     */
27
-    public function id(): string;
22
+	/**
23
+	 * Get the map ID
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public function id(): string;
28 28
 
29
-    /**
30
-     * Get the map title
31
-     *
32
-     * @return string
33
-     */
34
-    public function title(): string;
29
+	/**
30
+	 * Get the map title
31
+	 *
32
+	 * @return string
33
+	 */
34
+	public function title(): string;
35 35
 
36
-    /**
37
-     * Get the features in the map
38
-     *
39
-     * @return \Brick\Geo\IO\GeoJSON\Feature[]
40
-     */
41
-    public function features(): array;
36
+	/**
37
+	 * Get the features in the map
38
+	 *
39
+	 * @return \Brick\Geo\IO\GeoJSON\Feature[]
40
+	 */
41
+	public function features(): array;
42 42
 }
Please login to merge, or discard this patch.
app/Contracts/GeoDispersion/MapViewConfigInterface.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -19,26 +19,26 @@
 block discarded – undo
19 19
  */
20 20
 interface MapViewConfigInterface
21 21
 {
22
-    /**
23
-     * Get the feature property to be used for mapping the map feature with the analysis results
24
-     *
25
-     * @return string
26
-     */
27
-    public function mapMappingProperty(): string;
22
+	/**
23
+	 * Get the feature property to be used for mapping the map feature with the analysis results
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public function mapMappingProperty(): string;
28 28
 
29
-    /**
30
-     * Get the config of the mapper associated with the map view
31
-     *
32
-     * @return PlaceMapperConfigInterface
33
-     */
34
-    public function mapperConfig(): PlaceMapperConfigInterface;
29
+	/**
30
+	 * Get the config of the mapper associated with the map view
31
+	 *
32
+	 * @return PlaceMapperConfigInterface
33
+	 */
34
+	public function mapperConfig(): PlaceMapperConfigInterface;
35 35
 
36
-    /**
37
-     * Get a MapViewConfigInterface object with the new properties
38
-     *
39
-     * @param string $mapping_property
40
-     * @param PlaceMapperConfigInterface $mapper_config
41
-     * @return static
42
-     */
43
-    public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self;
36
+	/**
37
+	 * Get a MapViewConfigInterface object with the new properties
38
+	 *
39
+	 * @param string $mapping_property
40
+	 * @param PlaceMapperConfigInterface $mapper_config
41
+	 * @return static
42
+	 */
43
+	public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self;
44 44
 }
Please login to merge, or discard this patch.
app/Contracts/GeoDispersion/PlaceMapperInterface.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -22,54 +22,54 @@
 block discarded – undo
22 22
  */
23 23
 interface PlaceMapperInterface
24 24
 {
25
-    /**
26
-     * Get the Place mapper title
27
-     *
28
-     * @return string
29
-     */
30
-    public function title(): string;
25
+	/**
26
+	 * Get the Place mapper title
27
+	 *
28
+	 * @return string
29
+	 */
30
+	public function title(): string;
31 31
 
32
-    /**
33
-     * Boot the Place mapper
34
-     */
35
-    public function boot(): void;
32
+	/**
33
+	 * Boot the Place mapper
34
+	 */
35
+	public function boot(): void;
36 36
 
37
-    /**
38
-     * Get the configuration associated to the mapper
39
-     *
40
-     * @return PlaceMapperConfigInterface
41
-     */
42
-    public function config(): PlaceMapperConfigInterface;
37
+	/**
38
+	 * Get the configuration associated to the mapper
39
+	 *
40
+	 * @return PlaceMapperConfigInterface
41
+	 */
42
+	public function config(): PlaceMapperConfigInterface;
43 43
 
44
-    /**
45
-     * Set the configured associated to the mapper
46
-     *
47
-     * @param PlaceMapperConfigInterface $config
48
-     */
49
-    public function setConfig(PlaceMapperConfigInterface $config): void;
44
+	/**
45
+	 * Set the configured associated to the mapper
46
+	 *
47
+	 * @param PlaceMapperConfigInterface $config
48
+	 */
49
+	public function setConfig(PlaceMapperConfigInterface $config): void;
50 50
 
51
-    /**
52
-     * Get the data associated to the mapper, for a specific key
53
-     *
54
-     * @param string $key
55
-     * @return null|mixed
56
-     */
57
-    public function data(string $key);
51
+	/**
52
+	 * Get the data associated to the mapper, for a specific key
53
+	 *
54
+	 * @param string $key
55
+	 * @return null|mixed
56
+	 */
57
+	public function data(string $key);
58 58
 
59
-    /**
60
-     * Set the data associated to the mapper, for a specific key
61
-     *
62
-     * @param string $key
63
-     * @param mixed $data
64
-     */
65
-    public function setData(string $key, $data): void;
59
+	/**
60
+	 * Set the data associated to the mapper, for a specific key
61
+	 *
62
+	 * @param string $key
63
+	 * @param mixed $data
64
+	 */
65
+	public function setData(string $key, $data): void;
66 66
 
67
-    /**
68
-     * Return the property value of the feature identifying a place in a GeoJson map.
69
-     *
70
-     * @param Place $place
71
-     * @param string $feature_property
72
-     * @return string|NULL
73
-     */
74
-    public function map(Place $place, string $feature_property): ?string;
67
+	/**
68
+	 * Return the property value of the feature identifying a place in a GeoJson map.
69
+	 *
70
+	 * @param Place $place
71
+	 * @param string $feature_property
72
+	 * @return string|NULL
73
+	 */
74
+	public function map(Place $place, string $feature_property): ?string;
75 75
 }
Please login to merge, or discard this patch.
app/Contracts/GeoDispersion/PlaceMapperConfigInterface.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -24,45 +24,45 @@
 block discarded – undo
24 24
  */
25 25
 interface PlaceMapperConfigInterface extends JsonSerializable
26 26
 {
27
-    /**
28
-     * Deserialise the mapper configuration from a string or an array
29
-     *
30
-     * @param mixed $config
31
-     * @return $this
32
-     */
33
-    public function jsonDeserialize($config): self;
27
+	/**
28
+	 * Deserialise the mapper configuration from a string or an array
29
+	 *
30
+	 * @param mixed $config
31
+	 * @return $this
32
+	 */
33
+	public function jsonDeserialize($config): self;
34 34
 
35
-    /**
36
-     * Check if the configuration contains a specific key
37
-     *
38
-     * @param string $key
39
-     * @return bool
40
-     */
41
-    public function has(string $key): bool;
35
+	/**
36
+	 * Check if the configuration contains a specific key
37
+	 *
38
+	 * @param string $key
39
+	 * @return bool
40
+	 */
41
+	public function has(string $key): bool;
42 42
 
43
-    /**
44
-     * Return the configuration associated with a key, or a default value if none found.
45
-     *
46
-     * @param string $key
47
-     * @param mixed|null $default
48
-     * @return mixed|null
49
-     */
50
-    public function get(string $key, $default = null);
43
+	/**
44
+	 * Return the configuration associated with a key, or a default value if none found.
45
+	 *
46
+	 * @param string $key
47
+	 * @param mixed|null $default
48
+	 * @return mixed|null
49
+	 */
50
+	public function get(string $key, $default = null);
51 51
 
52
-    /**
53
-     * Return the content of the mapper configuration section of the config page
54
-     *
55
-     * @param ModuleInterface $module
56
-     * @param Tree $tree
57
-     * @return string
58
-     */
59
-    public function configContent(ModuleInterface $module, Tree $tree): string;
52
+	/**
53
+	 * Return the content of the mapper configuration section of the config page
54
+	 *
55
+	 * @param ModuleInterface $module
56
+	 * @param Tree $tree
57
+	 * @return string
58
+	 */
59
+	public function configContent(ModuleInterface $module, Tree $tree): string;
60 60
 
61
-    /**
62
-     * Return a PlaceMapperConfigInterface object updated according to its mapper configuration rules
63
-     *
64
-     * @param ServerRequestInterface $request
65
-     * @return static
66
-     */
67
-    public function withConfigUpdate(ServerRequestInterface $request): self;
61
+	/**
62
+	 * Return a PlaceMapperConfigInterface object updated according to its mapper configuration rules
63
+	 *
64
+	 * @param ServerRequestInterface $request
65
+	 * @return static
66
+	 */
67
+	public function withConfigUpdate(ServerRequestInterface $request): self;
68 68
 }
Please login to merge, or discard this patch.
app/Contracts/Tasks/TaskInterface.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,25 +19,25 @@
 block discarded – undo
19 19
  */
20 20
 interface TaskInterface
21 21
 {
22
-    /**
23
-     * Display name of the task
24
-     *
25
-     * @return string
26
-     */
27
-    public function name(): string;
22
+	/**
23
+	 * Display name of the task
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public function name(): string;
28 28
     
29
-    /**
30
-     * Return the default frequency for the execution of the task, in minutes.
31
-     *
32
-     * @return int Frequency for the execution of the task
33
-     */
34
-    public function defaultFrequency(): int;
29
+	/**
30
+	 * Return the default frequency for the execution of the task, in minutes.
31
+	 *
32
+	 * @return int Frequency for the execution of the task
33
+	 */
34
+	public function defaultFrequency(): int;
35 35
     
36
-    /**
37
-     * Run the task's actions, and return whether the execution has been successful.
38
-     *
39
-     * @param TaskSchedule $task_schedule
40
-     * @return bool Has the execution been a success
41
-     */
42
-    public function run(TaskSchedule $task_schedule): bool;
36
+	/**
37
+	 * Run the task's actions, and return whether the execution has been successful.
38
+	 *
39
+	 * @param TaskSchedule $task_schedule
40
+	 * @return bool Has the execution been a success
41
+	 */
42
+	public function run(TaskSchedule $task_schedule): bool;
43 43
 }
Please login to merge, or discard this patch.
app/Module/PatronymicLineage/Model/LineageNode.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function addFamily(Family $fams): object
69 69
     {
70 70
         if (!$this->linked_fams->has($fams->xref())) {
71
-            $this->linked_fams->put($fams->xref(), (object) [
71
+            $this->linked_fams->put($fams->xref(), (object)[
72 72
                 'family'   =>  $fams,
73 73
                 'children' =>  new Collection()
74 74
             ]);
@@ -135,6 +135,6 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function hasFollowUpSurname(): bool
137 137
     {
138
-        return mb_strlen($this->followUpSurname()) > 0 ;
138
+        return mb_strlen($this->followUpSurname()) > 0;
139 139
     }
140 140
 }
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -24,106 +24,106 @@
 block discarded – undo
24 24
  */
25 25
 class LineageNode
26 26
 {
27
-    /**
28
-     * @var Collection<string, stdClass>  $linked_fams Spouse families linked to the node
29
-     */
30
-    private Collection $linked_fams;
27
+	/**
28
+	 * @var Collection<string, stdClass>  $linked_fams Spouse families linked to the node
29
+	 */
30
+	private Collection $linked_fams;
31 31
 
32
-    private ?Individual $node_indi;
33
-    private LineageRootNode $root_node;
34
-    private ?string $alt_surname;
32
+	private ?Individual $node_indi;
33
+	private LineageRootNode $root_node;
34
+	private ?string $alt_surname;
35 35
 
36
-    /**
37
-     * Constructor for Lineage node
38
-     *
39
-     * @param Individual $node_indi Main individual
40
-     * @param LineageRootNode $root_node Node of the lineage root
41
-     * @param null|string $alt_surname Follow-up surname
42
-     */
43
-    public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
44
-    {
45
-        $this->node_indi = $node_indi;
46
-        $this->root_node = $root_node;
47
-        $this->alt_surname = $alt_surname;
48
-        $this->linked_fams = new Collection();
49
-    }
36
+	/**
37
+	 * Constructor for Lineage node
38
+	 *
39
+	 * @param Individual $node_indi Main individual
40
+	 * @param LineageRootNode $root_node Node of the lineage root
41
+	 * @param null|string $alt_surname Follow-up surname
42
+	 */
43
+	public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null)
44
+	{
45
+		$this->node_indi = $node_indi;
46
+		$this->root_node = $root_node;
47
+		$this->alt_surname = $alt_surname;
48
+		$this->linked_fams = new Collection();
49
+	}
50 50
 
51
-    /**
52
-     * Add a spouse family to the node
53
-     *
54
-     * @param Family $fams
55
-     * @return stdClass
56
-     */
57
-    public function addFamily(Family $fams): object
58
-    {
59
-        if (!$this->linked_fams->has($fams->xref())) {
60
-            $this->linked_fams->put($fams->xref(), (object) [
61
-                'family'   =>  $fams,
62
-                'children' =>  new Collection()
63
-            ]);
64
-        }
65
-        return $this->linked_fams->get($fams->xref());
66
-    }
51
+	/**
52
+	 * Add a spouse family to the node
53
+	 *
54
+	 * @param Family $fams
55
+	 * @return stdClass
56
+	 */
57
+	public function addFamily(Family $fams): object
58
+	{
59
+		if (!$this->linked_fams->has($fams->xref())) {
60
+			$this->linked_fams->put($fams->xref(), (object) [
61
+				'family'   =>  $fams,
62
+				'children' =>  new Collection()
63
+			]);
64
+		}
65
+		return $this->linked_fams->get($fams->xref());
66
+	}
67 67
 
68
-    /**
69
-     * Add a child LineageNode to the node
70
-     *
71
-     * @param Family $fams
72
-     * @param LineageNode $child
73
-     */
74
-    public function addChild(Family $fams, LineageNode $child = null): void
75
-    {
76
-        $this->addFamily($fams)->children->push($child);
77
-        $this->root_node->incrementChildNodes();
78
-    }
68
+	/**
69
+	 * Add a child LineageNode to the node
70
+	 *
71
+	 * @param Family $fams
72
+	 * @param LineageNode $child
73
+	 */
74
+	public function addChild(Family $fams, LineageNode $child = null): void
75
+	{
76
+		$this->addFamily($fams)->children->push($child);
77
+		$this->root_node->incrementChildNodes();
78
+	}
79 79
 
80
-    /**
81
-     * Returns the node individual
82
-     *
83
-     * @return Individual|NULL
84
-     */
85
-    public function individual(): ?Individual
86
-    {
87
-        return $this->node_indi;
88
-    }
80
+	/**
81
+	 * Returns the node individual
82
+	 *
83
+	 * @return Individual|NULL
84
+	 */
85
+	public function individual(): ?Individual
86
+	{
87
+		return $this->node_indi;
88
+	}
89 89
 
90
-    /**
91
-     * Returns the lineage root node individual
92
-     *
93
-     * @return LineageRootNode
94
-     */
95
-    public function rootNode(): LineageRootNode
96
-    {
97
-        return $this->root_node;
98
-    }
90
+	/**
91
+	 * Returns the lineage root node individual
92
+	 *
93
+	 * @return LineageRootNode
94
+	 */
95
+	public function rootNode(): LineageRootNode
96
+	{
97
+		return $this->root_node;
98
+	}
99 99
 
100
-    /**
101
-     * Returns the spouse families linked to the node
102
-     *
103
-     * @return Collection<string, \stdClass>
104
-     */
105
-    public function families(): Collection
106
-    {
107
-        return $this->linked_fams;
108
-    }
100
+	/**
101
+	 * Returns the spouse families linked to the node
102
+	 *
103
+	 * @return Collection<string, \stdClass>
104
+	 */
105
+	public function families(): Collection
106
+	{
107
+		return $this->linked_fams;
108
+	}
109 109
 
110
-    /**
111
-     * Returns the follow-up surname
112
-     *
113
-     * @return string
114
-     */
115
-    public function followUpSurname(): string
116
-    {
117
-        return $this->alt_surname ?? '';
118
-    }
110
+	/**
111
+	 * Returns the follow-up surname
112
+	 *
113
+	 * @return string
114
+	 */
115
+	public function followUpSurname(): string
116
+	{
117
+		return $this->alt_surname ?? '';
118
+	}
119 119
 
120
-    /**
121
-     * Indicates whether the node has a follow up surname
122
-     *
123
-     * @return boolean
124
-     */
125
-    public function hasFollowUpSurname(): bool
126
-    {
127
-        return mb_strlen($this->followUpSurname()) > 0 ;
128
-    }
120
+	/**
121
+	 * Indicates whether the node has a follow up surname
122
+	 *
123
+	 * @return boolean
124
+	 */
125
+	public function hasFollowUpSurname(): bool
126
+	{
127
+		return mb_strlen($this->followUpSurname()) > 0 ;
128
+	}
129 129
 }
Please login to merge, or discard this patch.
app/Module/WelcomeBlock/Http/RequestHandlers/MatomoStats.php 2 patches
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.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -32,64 +32,64 @@
 block discarded – undo
32 32
  */
33 33
 class MatomoStats implements RequestHandlerInterface
34 34
 {
35
-    use ViewResponseTrait;
35
+	use ViewResponseTrait;
36 36
 
37
-    /**
38
-     * @var WelcomeBlockModule|null $module
39
-     */
40
-    private $module;
37
+	/**
38
+	 * @var WelcomeBlockModule|null $module
39
+	 */
40
+	private $module;
41 41
 
42
-    /**
43
-     * @var MatomoStatsService $matomo_service
44
-     */
45
-    private $matomo_service;
42
+	/**
43
+	 * @var MatomoStatsService $matomo_service
44
+	 */
45
+	private $matomo_service;
46 46
 
47
-    /**
48
-     * Constructor for MatomoStats request handler
49
-     * @param ModuleService $module_service
50
-     * @param MatomoStatsService $matomo_service
51
-     */
52
-    public function __construct(
53
-        ModuleService $module_service,
54
-        MatomoStatsService $matomo_service
55
-    ) {
56
-        $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
57
-        $this->matomo_service = $matomo_service;
58
-    }
47
+	/**
48
+	 * Constructor for MatomoStats request handler
49
+	 * @param ModuleService $module_service
50
+	 * @param MatomoStatsService $matomo_service
51
+	 */
52
+	public function __construct(
53
+		ModuleService $module_service,
54
+		MatomoStatsService $matomo_service
55
+	) {
56
+		$this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
57
+		$this->matomo_service = $matomo_service;
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritDoc}
62
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
63
-     */
64
-    public function handle(ServerRequestInterface $request): ResponseInterface
65
-    {
66
-        $this->layout = 'layouts/ajax';
60
+	/**
61
+	 * {@inheritDoc}
62
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
63
+	 */
64
+	public function handle(ServerRequestInterface $request): ResponseInterface
65
+	{
66
+		$this->layout = 'layouts/ajax';
67 67
 
68
-        if ($this->module === null) {
69
-            return $this->viewResponse('errors/unhandled-exception', [
70
-                'error' => 'The attached module could not be found.'
71
-            ], StatusCodeInterface::STATUS_NOT_FOUND);
72
-        }
68
+		if ($this->module === null) {
69
+			return $this->viewResponse('errors/unhandled-exception', [
70
+				'error' => 'The attached module could not be found.'
71
+			], StatusCodeInterface::STATUS_NOT_FOUND);
72
+		}
73 73
 
74
-        $block_id = Validator::attributes($request)->integer('block_id', -1);
75
-        $nb_visits_year = $nb_visits_today = null;
74
+		$block_id = Validator::attributes($request)->integer('block_id', -1);
75
+		$nb_visits_year = $nb_visits_today = null;
76 76
 
77
-        try {
78
-            if ($block_id !== -1 && $this->module->isMatomoEnabled($block_id)) {
79
-                $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
80
-                $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
81
-                    + $nb_visits_today;
82
-            }
83
-        } catch (Throwable $ex) {
84
-            return $this->viewResponse('errors/unhandled-exception', [
85
-                'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
86
-                    (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
87
-            ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
88
-        }
77
+		try {
78
+			if ($block_id !== -1 && $this->module->isMatomoEnabled($block_id)) {
79
+				$nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
80
+				$nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
81
+					+ $nb_visits_today;
82
+			}
83
+		} catch (Throwable $ex) {
84
+			return $this->viewResponse('errors/unhandled-exception', [
85
+				'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
86
+					(Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
87
+			], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
88
+		}
89 89
 
90
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
91
-            'visits_year'   =>  $nb_visits_year,
92
-            'visits_today'  =>  $nb_visits_today
93
-        ]);
94
-    }
90
+		return $this->viewResponse($this->module->name() . '::matomo-stats', [
91
+			'visits_year'   =>  $nb_visits_year,
92
+			'visits_today'  =>  $nb_visits_today
93
+		]);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
app/Module/WelcomeBlock/Services/MatomoStatsService.php 2 patches
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.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -29,113 +29,113 @@
 block discarded – undo
29 29
  */
30 30
 class MatomoStatsService
31 31
 {
32
-    protected ?HandlerStack $handler = null;
32
+	protected ?HandlerStack $handler = null;
33 33
 
34
-    /**
35
-     * Set or get the http handler for the service
36
-     *
37
-     * @param HandlerStack $handler
38
-     * @return HandlerStack
39
-     */
40
-    public function httpHandler(HandlerStack $handler = null): HandlerStack
41
-    {
42
-        if ($this->handler === null) {
43
-            $this->handler = HandlerStack::create();
44
-        }
45
-        if ($handler !== null) {
46
-            $this->handler = $handler;
47
-        }
48
-        return $this->handler;
49
-    }
34
+	/**
35
+	 * Set or get the http handler for the service
36
+	 *
37
+	 * @param HandlerStack $handler
38
+	 * @return HandlerStack
39
+	 */
40
+	public function httpHandler(HandlerStack $handler = null): HandlerStack
41
+	{
42
+		if ($this->handler === null) {
43
+			$this->handler = HandlerStack::create();
44
+		}
45
+		if ($handler !== null) {
46
+			$this->handler = $handler;
47
+		}
48
+		return $this->handler;
49
+	}
50 50
 
51
-    /**
52
-     * Returns the number of visits for the current year (up to the day before).
53
-     * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
54
-     *
55
-     * @param WelcomeBlockModule $module
56
-     * @param int $block_id
57
-     * @return int|NULL
58
-     */
59
-    public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
60
-    {
61
-        return Registry::cache()->file()->remember(
62
-            $module->name() . '-matomovisits-yearly-' . $block_id,
63
-            function () use ($module, $block_id): ?int {
64
-                $visits_year = $this->visits($module, $block_id, 'year');
65
-                if ($visits_year === null) {
66
-                    return null;
67
-                }
68
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
51
+	/**
52
+	 * Returns the number of visits for the current year (up to the day before).
53
+	 * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
54
+	 *
55
+	 * @param WelcomeBlockModule $module
56
+	 * @param int $block_id
57
+	 * @return int|NULL
58
+	 */
59
+	public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
60
+	{
61
+		return Registry::cache()->file()->remember(
62
+			$module->name() . '-matomovisits-yearly-' . $block_id,
63
+			function () use ($module, $block_id): ?int {
64
+				$visits_year = $this->visits($module, $block_id, 'year');
65
+				if ($visits_year === null) {
66
+					return null;
67
+				}
68
+				$visits_today = (int) $this->visits($module, $block_id, 'day');
69 69
 
70
-                return $visits_year - $visits_today;
71
-            },
72
-            Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
73
-        );
74
-    }
70
+				return $visits_year - $visits_today;
71
+			},
72
+			Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
73
+		);
74
+	}
75 75
 
76
-    /**
77
-     * Returns the number of visits for the current day.
78
-     *
79
-     * @param WelcomeBlockModule $module
80
-     * @param int $block_id
81
-     * @return int|NULL
82
-     */
83
-    public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
84
-    {
85
-        return Registry::cache()->array()->remember(
86
-            $module->name() . '-matomovisits-daily-' . $block_id,
87
-            function () use ($module, $block_id): ?int {
88
-                return $this->visits($module, $block_id, 'day');
89
-            }
90
-        );
91
-    }
76
+	/**
77
+	 * Returns the number of visits for the current day.
78
+	 *
79
+	 * @param WelcomeBlockModule $module
80
+	 * @param int $block_id
81
+	 * @return int|NULL
82
+	 */
83
+	public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
84
+	{
85
+		return Registry::cache()->array()->remember(
86
+			$module->name() . '-matomovisits-daily-' . $block_id,
87
+			function () use ($module, $block_id): ?int {
88
+				return $this->visits($module, $block_id, 'day');
89
+			}
90
+		);
91
+	}
92 92
 
93
-    /**
94
-     * Invoke the Matomo API to retrieve the number of visits over a period.
95
-     *
96
-     * @param WelcomeBlockModule $module
97
-     * @param int $block_id
98
-     * @param string $period
99
-     * @return int|NULL
100
-     */
101
-    protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
102
-    {
103
-        $settings = $module->matomoSettings($block_id);
93
+	/**
94
+	 * Invoke the Matomo API to retrieve the number of visits over a period.
95
+	 *
96
+	 * @param WelcomeBlockModule $module
97
+	 * @param int $block_id
98
+	 * @param string $period
99
+	 * @return int|NULL
100
+	 */
101
+	protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
102
+	{
103
+		$settings = $module->matomoSettings($block_id);
104 104
 
105
-        if (
106
-            $settings['matomo_enabled'] === true
107
-            && mb_strlen($settings['matomo_url']) > 0
108
-            && mb_strlen($settings['matomo_token']) > 0
109
-            && $settings['matomo_siteid'] > 0
110
-        ) {
111
-            try {
112
-                $http_client = new Client([
113
-                    RequestOptions::TIMEOUT => 30,
114
-                    'handler'   => $this->handler
115
-                ]);
105
+		if (
106
+			$settings['matomo_enabled'] === true
107
+			&& mb_strlen($settings['matomo_url']) > 0
108
+			&& mb_strlen($settings['matomo_token']) > 0
109
+			&& $settings['matomo_siteid'] > 0
110
+		) {
111
+			try {
112
+				$http_client = new Client([
113
+					RequestOptions::TIMEOUT => 30,
114
+					'handler'   => $this->handler
115
+				]);
116 116
 
117
-                $response = $http_client->get($settings['matomo_url'], [
118
-                    'query' =>  [
119
-                        'module'    =>  'API',
120
-                        'method'    =>  'VisitsSummary.getVisits',
121
-                        'idSite'    =>  $settings['matomo_siteid'],
122
-                        'period'    =>  $period,
123
-                        'date'      =>  'today',
124
-                        'token_auth' =>  $settings['matomo_token'],
125
-                        'format'    =>  'json'
126
-                    ]
127
-                ]);
117
+				$response = $http_client->get($settings['matomo_url'], [
118
+					'query' =>  [
119
+						'module'    =>  'API',
120
+						'method'    =>  'VisitsSummary.getVisits',
121
+						'idSite'    =>  $settings['matomo_siteid'],
122
+						'period'    =>  $period,
123
+						'date'      =>  'today',
124
+						'token_auth' =>  $settings['matomo_token'],
125
+						'format'    =>  'json'
126
+					]
127
+				]);
128 128
 
129
-                if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
130
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
131
-                    if ($result !== null) {
132
-                        return (int)$result;
133
-                    }
134
-                }
135
-            } catch (GuzzleException $ex) {
136
-            }
137
-        }
129
+				if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
130
+					$result = json_decode((string) $response->getBody(), true)['value'] ?? null;
131
+					if ($result !== null) {
132
+						return (int)$result;
133
+					}
134
+				}
135
+			} catch (GuzzleException $ex) {
136
+			}
137
+		}
138 138
 
139
-        return null;
140
-    }
139
+		return null;
140
+	}
141 141
 }
Please login to merge, or discard this patch.