Passed
Push — feature/code-analysis ( 4fe35d...c99b5b )
by Jonathan
11:08 queued 07:29
created
app/Module/GeoDispersion/Services/PlacesReferenceTableService.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,102 +21,102 @@
 block discarded – undo
21 21
  */
22 22
 class PlacesReferenceTableService
23 23
 {
24
-    /**
25
-     * Mapping format placeholder tags => table column names
26
-     * @var array<string, string>
27
-     */
28
-    private const COLUMN_MAPPING = [
29
-        'name'  =>  'majgr_place_name',
30
-        'id'    =>  'majgr_place_admin_id',
31
-        'zip'   =>  'majgr_place_zip',
32
-        'gov'   =>  'majgr_place_gov_id',
33
-        'mls'   =>  'majgr_place_mls_id'
34
-    ];
24
+	/**
25
+	 * Mapping format placeholder tags => table column names
26
+	 * @var array<string, string>
27
+	 */
28
+	private const COLUMN_MAPPING = [
29
+		'name'  =>  'majgr_place_name',
30
+		'id'    =>  'majgr_place_admin_id',
31
+		'zip'   =>  'majgr_place_zip',
32
+		'gov'   =>  'majgr_place_gov_id',
33
+		'mls'   =>  'majgr_place_mls_id'
34
+	];
35 35
 
36
-    /**
37
-     * Get the formatted target mapping value of a place defined by a source format.
38
-     *
39
-     * @param string $source
40
-     * @param string $source_format
41
-     * @param string $target_format
42
-     * @return string|NULL
43
-     */
44
-    public function targetId(string $source, string $source_format, string $target_format): ?string
45
-    {
46
-        // Extract parts for the WHERE clause
47
-        $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
-        $source_parts = preg_split('/[{}]/i', $source_format);
49
-        if ($source_parts === false) {
50
-            return null;
51
-        }
52
-        $source_parts = array_map(function (string $part): string {
53
-            if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
-                return $this->columnName($column_id[1]);
55
-            }
56
-            return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
-        }, array_filter($source_parts));
58
-        $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
36
+	/**
37
+	 * Get the formatted target mapping value of a place defined by a source format.
38
+	 *
39
+	 * @param string $source
40
+	 * @param string $source_format
41
+	 * @param string $target_format
42
+	 * @return string|NULL
43
+	 */
44
+	public function targetId(string $source, string $source_format, string $target_format): ?string
45
+	{
46
+		// Extract parts for the WHERE clause
47
+		$source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
+		$source_parts = preg_split('/[{}]/i', $source_format);
49
+		if ($source_parts === false) {
50
+			return null;
51
+		}
52
+		$source_parts = array_map(function (string $part): string {
53
+			if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
+				return $this->columnName($column_id[1]);
55
+			}
56
+			return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
+		}, array_filter($source_parts));
58
+		$source_parts[] = "'%'";
59
+		$concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
60 60
 
61
-        // Extract columns used in target
62
-        $columns = [];
63
-        if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
-            $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
-        }
61
+		// Extract columns used in target
62
+		$columns = [];
63
+		if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
+			$columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
+		}
66 66
 
67
-        // Get the mapping
68
-        $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
-            ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
-            ->get();
67
+		// Get the mapping
68
+		$rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
+			->select($columns)
70
+			->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
+			->get();
72 72
 
73
-        // Format the output ID
74
-        if ($rows->count() === 0) {
75
-            return null;
76
-        }
73
+		// Format the output ID
74
+		if ($rows->count() === 0) {
75
+			return null;
76
+		}
77 77
 
78
-        $mapping = (array) $rows->first();
79
-        if (count($columns_select) === 0) {
80
-            return $target_format;
81
-        }
78
+		$mapping = (array) $rows->first();
79
+		if (count($columns_select) === 0) {
80
+			return $target_format;
81
+		}
82 82
 
83
-        return str_replace(
84
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
-            array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
-            $target_format
87
-        );
88
-    }
83
+		return str_replace(
84
+			array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
+			array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
+			$target_format
87
+		);
88
+	}
89 89
 
90
-    /**
91
-     * Get the column name for a format placeholder tag
92
-     *
93
-     * @param string $placeholder
94
-     * @return string
95
-     */
96
-    private function columnName(string $placeholder): string
97
-    {
98
-        return self::COLUMN_MAPPING[$placeholder] ?? '';
99
-    }
90
+	/**
91
+	 * Get the column name for a format placeholder tag
92
+	 *
93
+	 * @param string $placeholder
94
+	 * @return string
95
+	 */
96
+	private function columnName(string $placeholder): string
97
+	{
98
+		return self::COLUMN_MAPPING[$placeholder] ?? '';
99
+	}
100 100
 
101
-    /**
102
-     * Get the placeholder tag for a column_name
103
-     *
104
-     * @param string $column_name
105
-     * @return string
106
-     */
107
-    private function tagName(string $column_name): string
108
-    {
109
-        return array_flip(self::COLUMN_MAPPING)[$column_name] ?? '';
110
-    }
101
+	/**
102
+	 * Get the placeholder tag for a column_name
103
+	 *
104
+	 * @param string $column_name
105
+	 * @return string
106
+	 */
107
+	private function tagName(string $column_name): string
108
+	{
109
+		return array_flip(self::COLUMN_MAPPING)[$column_name] ?? '';
110
+	}
111 111
 
112
-    /**
113
-     * Sanitize string for use in a SQL query.
114
-     *
115
-     * @param string $string
116
-     * @return string
117
-     */
118
-    private function sanitizeString(string $string): string
119
-    {
120
-        return DB::connection()->getPdo()->quote($string);
121
-    }
112
+	/**
113
+	 * Sanitize string for use in a SQL query.
114
+	 *
115
+	 * @param string $string
116
+	 * @return string
117
+	 */
118
+	private function sanitizeString(string $string): string
119
+	{
120
+		return DB::connection()->getPdo()->quote($string);
121
+	}
122 122
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/GeoAnalyses/AllEventsByTypeGeoAnalysis.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -26,55 +26,55 @@
 block discarded – undo
26 26
  */
27 27
 class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface
28 28
 {
29
-    private GeoAnalysisDataService $geoanalysis_data_service;
29
+	private GeoAnalysisDataService $geoanalysis_data_service;
30 30
 
31
-    /**
32
-     * Constructor for AllEventsByTypeGeoAnalysis
33
-     *
34
-     * @param GeoAnalysisDataService $geoanalysis_data_service
35
-     */
36
-    public function __construct(GeoAnalysisDataService $geoanalysis_data_service)
37
-    {
38
-        $this->geoanalysis_data_service = $geoanalysis_data_service;
39
-    }
31
+	/**
32
+	 * Constructor for AllEventsByTypeGeoAnalysis
33
+	 *
34
+	 * @param GeoAnalysisDataService $geoanalysis_data_service
35
+	 */
36
+	public function __construct(GeoAnalysisDataService $geoanalysis_data_service)
37
+	{
38
+		$this->geoanalysis_data_service = $geoanalysis_data_service;
39
+	}
40 40
 
41
-    /**
42
-     * {@inheritDoc}
43
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
44
-     */
45
-    public function title(): string
46
-    {
47
-        return I18N::translate('All events places by event type');
48
-    }
41
+	/**
42
+	 * {@inheritDoc}
43
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
44
+	 */
45
+	public function title(): string
46
+	{
47
+		return I18N::translate('All events places by event type');
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
53
-     */
54
-    public function itemsDescription(): callable
55
-    {
56
-        return fn(int $count): string => I18N::plural('event', 'events', $count);
57
-    }
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
53
+	 */
54
+	public function itemsDescription(): callable
55
+	{
56
+		return fn(int $count): string => I18N::plural('event', 'events', $count);
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
62
-     */
63
-    public function results(Tree $tree, int $depth): GeoAnalysisResults
64
-    {
65
-        $results = new GeoAnalysisResults();
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
62
+	 */
63
+	public function results(Tree $tree, int $depth): GeoAnalysisResults
64
+	{
65
+		$results = new GeoAnalysisResults();
66 66
 
67
-        foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) {
68
-            foreach ($record->facts([]) as $fact) {
69
-                $place = new GeoAnalysisPlace($tree, $fact->place(), $depth);
70
-                if ($place->isUnknown()) {
71
-                    continue;
72
-                }
73
-                $results->addPlace($place);
74
-                $results->addPlaceInCategory($fact->label(), 0, $place);
75
-            }
76
-        }
67
+		foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) {
68
+			foreach ($record->facts([]) as $fact) {
69
+				$place = new GeoAnalysisPlace($tree, $fact->place(), $depth);
70
+				if ($place->isUnknown()) {
71
+					continue;
72
+				}
73
+				$results->addPlace($place);
74
+				$results->addPlaceInCategory($fact->label(), 0, $place);
75
+			}
76
+		}
77 77
 
78
-        return $results;
79
-    }
78
+		return $results;
79
+	}
80 80
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/GeoAnalyses/AllEventsByCenturyGeoAnalysis.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -28,66 +28,66 @@
 block discarded – undo
28 28
  */
29 29
 class AllEventsByCenturyGeoAnalysis implements GeoAnalysisInterface
30 30
 {
31
-    private GeoAnalysisDataService $geoanalysis_data_service;
32
-    private CenturyService $century_service;
31
+	private GeoAnalysisDataService $geoanalysis_data_service;
32
+	private CenturyService $century_service;
33 33
 
34
-    /**
35
-     * Constructor for AllEventsByCenturyGeoAnalysis
36
-     *
37
-     * @param GeoAnalysisDataService $geoanalysis_data_service
38
-     * @param CenturyService $century_service
39
-     */
40
-    public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service)
41
-    {
42
-        $this->geoanalysis_data_service = $geoanalysis_data_service;
43
-        $this->century_service = $century_service;
44
-    }
34
+	/**
35
+	 * Constructor for AllEventsByCenturyGeoAnalysis
36
+	 *
37
+	 * @param GeoAnalysisDataService $geoanalysis_data_service
38
+	 * @param CenturyService $century_service
39
+	 */
40
+	public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service)
41
+	{
42
+		$this->geoanalysis_data_service = $geoanalysis_data_service;
43
+		$this->century_service = $century_service;
44
+	}
45 45
 
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
49
-     */
50
-    public function title(): string
51
-    {
52
-        return I18N::translate('All events places by century');
53
-    }
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
49
+	 */
50
+	public function title(): string
51
+	{
52
+		return I18N::translate('All events places by century');
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
58
-     */
59
-    public function itemsDescription(): callable
60
-    {
61
-        return fn(int $count): string => I18N::plural('event', 'events', $count);
62
-    }
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
58
+	 */
59
+	public function itemsDescription(): callable
60
+	{
61
+		return fn(int $count): string => I18N::plural('event', 'events', $count);
62
+	}
63 63
 
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
67
-     */
68
-    public function results(Tree $tree, int $depth): GeoAnalysisResults
69
-    {
70
-        $results = new GeoAnalysisResults();
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
67
+	 */
68
+	public function results(Tree $tree, int $depth): GeoAnalysisResults
69
+	{
70
+		$results = new GeoAnalysisResults();
71 71
 
72
-        foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) {
73
-            foreach ($record->facts([]) as $fact) {
74
-                $place = new GeoAnalysisPlace($tree, $fact->place(), $depth);
75
-                if ($place->isUnknown()) {
76
-                    continue;
77
-                }
78
-                $results->addPlace($place);
79
-                $date = $fact->date();
80
-                if ($date->isOK()) {
81
-                    $century = intdiv($date->gregorianYear(), 100);
82
-                    $results->addPlaceInCategory(
83
-                        I18N::translate('%s century', $this->century_service->centuryName($century)),
84
-                        $century,
85
-                        $place
86
-                    );
87
-                }
88
-            }
89
-        }
72
+		foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) {
73
+			foreach ($record->facts([]) as $fact) {
74
+				$place = new GeoAnalysisPlace($tree, $fact->place(), $depth);
75
+				if ($place->isUnknown()) {
76
+					continue;
77
+				}
78
+				$results->addPlace($place);
79
+				$date = $fact->date();
80
+				if ($date->isOK()) {
81
+					$century = intdiv($date->gregorianYear(), 100);
82
+					$results->addPlaceInCategory(
83
+						I18N::translate('%s century', $this->century_service->centuryName($century)),
84
+						$century,
85
+						$place
86
+					);
87
+				}
88
+			}
89
+		}
90 90
 
91
-        return $results;
92
-    }
91
+		return $results;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/PlaceMappers/SimplePlaceMapper.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -24,23 +24,23 @@
 block discarded – undo
24 24
  */
25 25
 class SimplePlaceMapper implements PlaceMapperInterface
26 26
 {
27
-    use PlaceMapperTrait;
27
+	use PlaceMapperTrait;
28 28
 
29
-    /**
30
-     * {@inheritDoc}
31
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
32
-     */
33
-    public function title(): string
34
-    {
35
-        return I18N::translate('Mapping on place name');
36
-    }
29
+	/**
30
+	 * {@inheritDoc}
31
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
32
+	 */
33
+	public function title(): string
34
+	{
35
+		return I18N::translate('Mapping on place name');
36
+	}
37 37
 
38
-    /**
39
-     * {@inheritDoc}
40
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
41
-     */
42
-    public function map(Place $place, string $feature_property): ?string
43
-    {
44
-        return $place->firstParts(1)->first();
45
-    }
38
+	/**
39
+	 * {@inheritDoc}
40
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
41
+	 */
42
+	public function map(Place $place, string $feature_property): ?string
43
+	{
44
+		return $place->firstParts(1)->first();
45
+	}
46 46
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/PlaceMappers/SimpleTopFilteredPlaceMapper.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -28,51 +28,51 @@
 block discarded – undo
28 28
  */
29 29
 class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface
30 30
 {
31
-    use TopFilteredPlaceMapperTrait;
31
+	use TopFilteredPlaceMapperTrait;
32 32
 
33
-    /**
34
-     * {@inheritDoc}
35
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title()
36
-     */
37
-    public function title(): string
38
-    {
39
-        return I18N::translate('Mapping on place name with filter');
40
-    }
33
+	/**
34
+	 * {@inheritDoc}
35
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title()
36
+	 */
37
+	public function title(): string
38
+	{
39
+		return I18N::translate('Mapping on place name with filter');
40
+	}
41 41
 
42
-    /**
43
-     * {@inheritDoc}
44
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot()
45
-     */
46
-    public function boot(): void
47
-    {
48
-        parent::boot();
49
-        $top_places = $this->config()->get('topPlaces');
50
-        if (is_array($top_places)) {
51
-            $this->setTopPlaces($top_places);
52
-        }
53
-    }
42
+	/**
43
+	 * {@inheritDoc}
44
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot()
45
+	 */
46
+	public function boot(): void
47
+	{
48
+		parent::boot();
49
+		$top_places = $this->config()->get('topPlaces');
50
+		if (is_array($top_places)) {
51
+			$this->setTopPlaces($top_places);
52
+		}
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config()
58
-     */
59
-    public function config(): PlaceMapperConfigInterface
60
-    {
61
-        if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) {
62
-            $this->setConfig(app(FilteredTopPlaceMapperConfig::class));
63
-        }
64
-        return parent::config();
65
-    }
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config()
58
+	 */
59
+	public function config(): PlaceMapperConfigInterface
60
+	{
61
+		if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) {
62
+			$this->setConfig(app(FilteredTopPlaceMapperConfig::class));
63
+		}
64
+		return parent::config();
65
+	}
66 66
 
67
-    /**
68
-     * {@inheritDoc}
69
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map()
70
-     */
71
-    public function map(Place $place, string $feature_property): ?string
72
-    {
73
-        if (!$this->belongsToTopLevels($place)) {
74
-            return null;
75
-        }
76
-        return parent::map($place, $feature_property);
77
-    }
67
+	/**
68
+	 * {@inheritDoc}
69
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map()
70
+	 */
71
+	public function map(Place $place, string $feature_property): ?string
72
+	{
73
+		if (!$this->belongsToTopLevels($place)) {
74
+			return null;
75
+		}
76
+		return parent::map($place, $feature_property);
77
+	}
78 78
 }
Please login to merge, or discard this patch.
app/Module/Certificates/Elements/SourceCertificate.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -28,61 +28,61 @@
 block discarded – undo
28 28
  */
29 29
 class SourceCertificate extends AbstractElement
30 30
 {
31
-    protected CertificatesModule $module;
32
-    protected CertificateFilesystemService $certif_filesystem;
33
-    protected UrlObfuscatorService $url_obfuscator_service;
31
+	protected CertificatesModule $module;
32
+	protected CertificateFilesystemService $certif_filesystem;
33
+	protected UrlObfuscatorService $url_obfuscator_service;
34 34
 
35
-    /**
36
-     * Constructor for SourceCertificate element
37
-     *
38
-     * @param string $label
39
-     * @param CertificatesModule $module
40
-     * @param CertificateFilesystemService $certif_filesystem
41
-     * @param UrlObfuscatorService $url_obfuscator_service
42
-     */
43
-    public function __construct(
44
-        string $label,
45
-        CertificatesModule $module,
46
-        CertificateFilesystemService $certif_filesystem = null,
47
-        UrlObfuscatorService $url_obfuscator_service = null
48
-    ) {
49
-        parent::__construct($label, null);
50
-        $this->module = $module;
51
-        $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class);
52
-        $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
53
-    }
35
+	/**
36
+	 * Constructor for SourceCertificate element
37
+	 *
38
+	 * @param string $label
39
+	 * @param CertificatesModule $module
40
+	 * @param CertificateFilesystemService $certif_filesystem
41
+	 * @param UrlObfuscatorService $url_obfuscator_service
42
+	 */
43
+	public function __construct(
44
+		string $label,
45
+		CertificatesModule $module,
46
+		CertificateFilesystemService $certif_filesystem = null,
47
+		UrlObfuscatorService $url_obfuscator_service = null
48
+	) {
49
+		parent::__construct($label, null);
50
+		$this->module = $module;
51
+		$this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class);
52
+		$this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical()
58
-     */
59
-    public function canonical($value): string
60
-    {
61
-        return strtr($value, '\\', '/');
62
-    }
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical()
58
+	 */
59
+	public function canonical($value): string
60
+	{
61
+		return strtr($value, '\\', '/');
62
+	}
63 63
 
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit()
67
-     */
68
-    public function edit(string $id, string $name, string $value, Tree $tree): string
69
-    {
70
-        list($city, $file) = explode('/', $this->canonical($value), 2) + ['', ''];
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit()
67
+	 */
68
+	public function edit(string $id, string $name, string $value, Tree $tree): string
69
+	{
70
+		list($city, $file) = explode('/', $this->canonical($value), 2) + ['', ''];
71 71
 
72
-        $cities = array_map(function (string $item): array {
73
-            return [$this->url_obfuscator_service->obfuscate($item), $item];
74
-        }, $this->certif_filesystem->cities($tree));
72
+		$cities = array_map(function (string $item): array {
73
+			return [$this->url_obfuscator_service->obfuscate($item), $item];
74
+		}, $this->certif_filesystem->cities($tree));
75 75
 
76
-        return view($this->module->name() . '::components/edit-certificate', [
77
-            'module_name'   =>  $this->module->name(),
78
-            'tree'          =>  $tree,
79
-            'id'            =>  $id,
80
-            'name'          =>  $name,
81
-            'cities'        =>  $cities,
82
-            'value'         =>  $this->canonical($value),
83
-            'value_city'    =>  $city,
84
-            'value_file'    =>  $file,
85
-            'js_script_url' =>  $this->module->assetUrl('js/certificates.min.js')
86
-        ]);
87
-    }
76
+		return view($this->module->name() . '::components/edit-certificate', [
77
+			'module_name'   =>  $this->module->name(),
78
+			'tree'          =>  $tree,
79
+			'id'            =>  $id,
80
+			'name'          =>  $name,
81
+			'cities'        =>  $cities,
82
+			'value'         =>  $this->canonical($value),
83
+			'value_city'    =>  $city,
84
+			'value_file'    =>  $file,
85
+			'js_script_url' =>  $this->module->assetUrl('js/certificates.min.js')
86
+		]);
87
+	}
88 88
 }
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/AdminConfigPage.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -29,47 +29,47 @@
 block discarded – undo
29 29
  */
30 30
 class AdminConfigPage implements RequestHandlerInterface
31 31
 {
32
-    use ViewResponseTrait;
32
+	use ViewResponseTrait;
33 33
 
34
-    private ?AdminTasksModule $module;
35
-    private TokenService $token_service;
34
+	private ?AdminTasksModule $module;
35
+	private TokenService $token_service;
36 36
 
37
-    /**
38
-     * Constructor for Admin Config request handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service, TokenService $token_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
-        $this->token_service = $token_service;
46
-    }
37
+	/**
38
+	 * Constructor for Admin Config request handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service, TokenService $token_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
+		$this->token_service = $token_service;
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
-     */
52
-    public function handle(ServerRequestInterface $request): ResponseInterface
53
-    {
54
-        $this->layout = 'layouts/administration';
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
+	 */
52
+	public function handle(ServerRequestInterface $request): ResponseInterface
53
+	{
54
+		$this->layout = 'layouts/administration';
55 55
 
56
-        if ($this->module === null) {
57
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
58
-        }
56
+		if ($this->module === null) {
57
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
58
+		}
59 59
 
60
-        $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
61
-        if ($token === '') {
62
-            $token = $this->token_service->generateRandomToken();
63
-            $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
64
-        }
60
+		$token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
61
+		if ($token === '') {
62
+			$token = $this->token_service->generateRandomToken();
63
+			$this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
64
+		}
65 65
 
66
-        return $this->viewResponse($this->module->name() . '::admin/config', [
67
-            'title'             =>  $this->module->title(),
68
-            'trigger_token'     =>  $token,
69
-            'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
70
-            'new_token_route'   =>  route(TokenGenerate::class),
71
-            'tasks_data_route'  =>  route(TasksList::class),
72
-            'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
73
-        ]);
74
-    }
66
+		return $this->viewResponse($this->module->name() . '::admin/config', [
67
+			'title'             =>  $this->module->title(),
68
+			'trigger_token'     =>  $token,
69
+			'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
70
+			'new_token_route'   =>  route(TokenGenerate::class),
71
+			'tasks_data_route'  =>  route(TasksList::class),
72
+			'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
73
+		]);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/TokenGenerate.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,34 +30,34 @@
 block discarded – undo
30 30
  */
31 31
 class TokenGenerate implements RequestHandlerInterface
32 32
 {
33
-    private ?AdminTasksModule $module;
34
-    private TokenService $token_service;
35
-
36
-    /**
37
-     * Constructor for TokenGenerate request handler
38
-     *
39
-     * @param ModuleService $module_service
40
-     */
41
-    public function __construct(ModuleService $module_service, TokenService $token_service)
42
-    {
43
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
44
-        $this->token_service = $token_service;
45
-    }
46
-
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        if ($this->module === null) {
54
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
-        }
56
-
57
-        $token = $this->token_service->generateRandomToken();
58
-        $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token);
59
-        Log::addConfigurationLog($this->module->title() . ' : New token generated.');
60
-
61
-        return response(['token' => $token]);
62
-    }
33
+	private ?AdminTasksModule $module;
34
+	private TokenService $token_service;
35
+
36
+	/**
37
+	 * Constructor for TokenGenerate request handler
38
+	 *
39
+	 * @param ModuleService $module_service
40
+	 */
41
+	public function __construct(ModuleService $module_service, TokenService $token_service)
42
+	{
43
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
44
+		$this->token_service = $token_service;
45
+	}
46
+
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		if ($this->module === null) {
54
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
55
+		}
56
+
57
+		$token = $this->token_service->generateRandomToken();
58
+		$this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token);
59
+		Log::addConfigurationLog($this->module->title() . ' : New token generated.');
60
+
61
+		return response(['token' => $token]);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
app/Module/AdminTasks/Services/TokenService.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -20,32 +20,32 @@
 block discarded – undo
20 20
  */
21 21
 class TokenService
22 22
 {
23
-    /**
24
-     * Returns a random-ish generated token of a given size
25
-     *
26
-     * @param int $length Length of the token, default to 32
27
-     * @return string Random token
28
-     */
29
-    public function generateRandomToken(int $length = 32): string
30
-    {
31
-        $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
32
-        $len_chars = count($chars);
33
-        $token = '';
34
-
35
-        for ($i = 0; $i < $length; $i++) {
36
-            $token .= $chars[mt_rand(0, $len_chars - 1)];
37
-        }
38
-
39
-        # Number of 32 char chunks
40
-        $chunks = ceil(strlen($token) / 32);
41
-        $md5token = '';
42
-
43
-        # Run each chunk through md5
44
-        for ($i = 1; $i <= $chunks; $i++) {
45
-            $md5token .= md5(substr($token, $i * 32 - 32, 32));
46
-        }
47
-
48
-        # Trim the token to the required length
49
-        return substr($md5token, 0, $length);
50
-    }
23
+	/**
24
+	 * Returns a random-ish generated token of a given size
25
+	 *
26
+	 * @param int $length Length of the token, default to 32
27
+	 * @return string Random token
28
+	 */
29
+	public function generateRandomToken(int $length = 32): string
30
+	{
31
+		$chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
32
+		$len_chars = count($chars);
33
+		$token = '';
34
+
35
+		for ($i = 0; $i < $length; $i++) {
36
+			$token .= $chars[mt_rand(0, $len_chars - 1)];
37
+		}
38
+
39
+		# Number of 32 char chunks
40
+		$chunks = ceil(strlen($token) / 32);
41
+		$md5token = '';
42
+
43
+		# Run each chunk through md5
44
+		for ($i = 1; $i <= $chunks; $i++) {
45
+			$md5token .= md5(substr($token, $i * 32 - 32, 32));
46
+		}
47
+
48
+		# Trim the token to the required length
49
+		return substr($md5token, 0, $length);
50
+	}
51 51
 }
Please login to merge, or discard this patch.