Passed
Push — main ( c808ff...64cea5 )
by Jonathan
03:30
created
app/Module/MiscExtensions/MiscExtensionsModule.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -34,93 +34,93 @@
 block discarded – undo
34 34
  * Provide miscellaneous improvements to webtrees.
35 35
  */
36 36
 class MiscExtensionsModule extends AbstractModule implements
37
-    ModuleMyArtJaubInterface,
38
-    ModuleConfigInterface,
39
-    ModuleHookSubscriberInterface
37
+	ModuleMyArtJaubInterface,
38
+	ModuleConfigInterface,
39
+	ModuleHookSubscriberInterface
40 40
 {
41
-    use ModuleMyArtJaubTrait {
42
-        boot as traitBoot;
43
-    }
44
-    use ModuleConfigTrait;
45
-
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
49
-     */
50
-    public function title(): string
51
-    {
52
-        return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
53
-    }
54
-
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
58
-     */
59
-    public function description(): string
60
-    {
61
-        //phpcs:ignore Generic.Files.LineLength.TooLong
62
-        return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
63
-    }
64
-
65
-    /**
66
-     * {@inheritDoc}
67
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
68
-     */
69
-    public function boot(): void
70
-    {
71
-        $this->traitBoot();
72
-        View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
73
-
74
-        if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
75
-            Registry::xrefFactory(new LegacyXrefFactory());
76
-        }
77
-    }
78
-
79
-    /**
80
-     * {@inheritDoc}
81
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
82
-     */
83
-    public function loadRoutes(Map $router): void
84
-    {
85
-        $router->attach('', '', static function (Map $router): void {
86
-
87
-            $router->attach('', '/module-maj/misc', static function (Map $router): void {
88
-
89
-                $router->attach('', '/config/admin', static function (Map $router): void {
90
-
91
-                    $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
92
-                    $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
93
-                });
94
-            });
95
-        });
96
-    }
97
-
98
-    /**
99
-     * {@inheritDoc}
100
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
101
-     */
102
-    public function customModuleVersion(): string
103
-    {
104
-        return '2.1.3-v.2';
105
-    }
106
-
107
-    /**
108
-     * {@inheritDoc}
109
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
110
-     */
111
-    public function getConfigLink(): string
112
-    {
113
-        return route(AdminConfigPage::class);
114
-    }
115
-
116
-    /**
117
-     * {@inheritDoc}
118
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
119
-     */
120
-    public function listSubscribedHooks(): array
121
-    {
122
-        return [
123
-            app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
124
-        ];
125
-    }
41
+	use ModuleMyArtJaubTrait {
42
+		boot as traitBoot;
43
+	}
44
+	use ModuleConfigTrait;
45
+
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
49
+	 */
50
+	public function title(): string
51
+	{
52
+		return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
53
+	}
54
+
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
58
+	 */
59
+	public function description(): string
60
+	{
61
+		//phpcs:ignore Generic.Files.LineLength.TooLong
62
+		return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
63
+	}
64
+
65
+	/**
66
+	 * {@inheritDoc}
67
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
68
+	 */
69
+	public function boot(): void
70
+	{
71
+		$this->traitBoot();
72
+		View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
73
+
74
+		if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
75
+			Registry::xrefFactory(new LegacyXrefFactory());
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * {@inheritDoc}
81
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
82
+	 */
83
+	public function loadRoutes(Map $router): void
84
+	{
85
+		$router->attach('', '', static function (Map $router): void {
86
+
87
+			$router->attach('', '/module-maj/misc', static function (Map $router): void {
88
+
89
+				$router->attach('', '/config/admin', static function (Map $router): void {
90
+
91
+					$router->get(AdminConfigPage::class, '', AdminConfigPage::class);
92
+					$router->post(AdminConfigAction::class, '', AdminConfigAction::class);
93
+				});
94
+			});
95
+		});
96
+	}
97
+
98
+	/**
99
+	 * {@inheritDoc}
100
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
101
+	 */
102
+	public function customModuleVersion(): string
103
+	{
104
+		return '2.1.3-v.2';
105
+	}
106
+
107
+	/**
108
+	 * {@inheritDoc}
109
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
110
+	 */
111
+	public function getConfigLink(): string
112
+	{
113
+		return route(AdminConfigPage::class);
114
+	}
115
+
116
+	/**
117
+	 * {@inheritDoc}
118
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
119
+	 */
120
+	public function listSubscribedHooks(): array
121
+	{
122
+		return [
123
+			app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
124
+		];
125
+	}
126 126
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
     public function boot(): void
70 70
     {
71 71
         $this->traitBoot();
72
-        View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
72
+        View::registerCustomView('::modules/privacy-policy/page', $this->name().'::privacy-policy');
73 73
 
74
-        if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
74
+        if ((int)$this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
75 75
             Registry::xrefFactory(new LegacyXrefFactory());
76 76
         }
77 77
     }
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function loadRoutes(Map $router): void
84 84
     {
85
-        $router->attach('', '', static function (Map $router): void {
85
+        $router->attach('', '', static function(Map $router): void {
86 86
 
87
-            $router->attach('', '/module-maj/misc', static function (Map $router): void {
87
+            $router->attach('', '/module-maj/misc', static function(Map $router): void {
88 88
 
89
-                $router->attach('', '/config/admin', static function (Map $router): void {
89
+                $router->attach('', '/config/admin', static function(Map $router): void {
90 90
 
91 91
                     $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
92 92
                     $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     public function listSubscribedHooks(): array
121 121
     {
122 122
         return [
123
-            app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
123
+            app()->makeWith(TitlesCardHook::class, ['module' => $this])
124 124
         ];
125 125
     }
126 126
 }
Please login to merge, or discard this patch.
app/Module/MiscExtensions/Factories/LegacyXrefFactory.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -23,67 +23,67 @@
 block discarded – undo
23 23
  */
24 24
 class LegacyXrefFactory extends XrefFactory
25 25
 {
26
-    protected const TYPE_TO_PREFIX = [
27
-        'INDI' => 'I',
28
-        'FAM'  => 'F',
29
-        'OBJE' => 'M',
30
-        'NOTE' => 'N',
31
-        'SOUR' => 'S',
32
-        'REPO' => 'R',
33
-    ];
26
+	protected const TYPE_TO_PREFIX = [
27
+		'INDI' => 'I',
28
+		'FAM'  => 'F',
29
+		'OBJE' => 'M',
30
+		'NOTE' => 'N',
31
+		'SOUR' => 'S',
32
+		'REPO' => 'R',
33
+	];
34 34
 
35
-    /**
36
-     * {@inheritDoc}
37
-     * @see \Fisharebest\Webtrees\Factories\XrefFactory::make()
38
-     */
39
-    public function make(string $record_type): string
40
-    {
41
-        $prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X';
35
+	/**
36
+	 * {@inheritDoc}
37
+	 * @see \Fisharebest\Webtrees\Factories\XrefFactory::make()
38
+	 */
39
+	public function make(string $record_type): string
40
+	{
41
+		$prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X';
42 42
 
43
-        return $this->generate($prefix, '');
44
-    }
43
+		return $this->generate($prefix, '');
44
+	}
45 45
 
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate()
49
-     */
50
-    protected function generate($prefix, $suffix): string
51
-    {
52
-        $tree = app(Tree::class);
53
-        if (!$tree instanceof Tree) {
54
-            return parent::generate($prefix, $suffix);
55
-        }
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate()
49
+	 */
50
+	protected function generate($prefix, $suffix): string
51
+	{
52
+		$tree = app(Tree::class);
53
+		if (!$tree instanceof Tree) {
54
+			return parent::generate($prefix, $suffix);
55
+		}
56 56
 
57
-        $setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix;
58
-        // Lock the row, so that only one new XREF may be generated at a time.
59
-        DB::table('gedcom_setting')
60
-            ->where('gedcom_id', '=', $tree->id())
61
-            ->where('setting_name', '=', $setting_name)
62
-            ->lockForUpdate()
63
-            ->get();
57
+		$setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix;
58
+		// Lock the row, so that only one new XREF may be generated at a time.
59
+		DB::table('gedcom_setting')
60
+			->where('gedcom_id', '=', $tree->id())
61
+			->where('setting_name', '=', $setting_name)
62
+			->lockForUpdate()
63
+			->get();
64 64
 
65
-        $increment = 1.0;
66
-        do {
67
-            $num = (int) $tree->getPreference($setting_name) + (int) $increment;
65
+		$increment = 1.0;
66
+		do {
67
+			$num = (int) $tree->getPreference($setting_name) + (int) $increment;
68 68
 
69
-            // This exponential increment allows us to scan over large blocks of
70
-            // existing data in a reasonable time.
71
-            $increment *= 1.01;
69
+			// This exponential increment allows us to scan over large blocks of
70
+			// existing data in a reasonable time.
71
+			$increment *= 1.01;
72 72
 
73
-            $xref = $prefix . $num . $suffix;
73
+			$xref = $prefix . $num . $suffix;
74 74
 
75
-            // Records may already exist with this sequence number.
76
-            $already_used =
77
-                DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() ||
78
-                DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() ||
79
-                DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() ||
80
-                DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() ||
81
-                DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() ||
82
-                DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists();
83
-        } while ($already_used);
75
+			// Records may already exist with this sequence number.
76
+			$already_used =
77
+				DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() ||
78
+				DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() ||
79
+				DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() ||
80
+				DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() ||
81
+				DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() ||
82
+				DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists();
83
+		} while ($already_used);
84 84
 
85
-        $tree->setPreference($setting_name, (string) $num);
85
+		$tree->setPreference($setting_name, (string) $num);
86 86
 
87
-        return $xref;
88
-    }
87
+		return $xref;
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             return parent::generate($prefix, $suffix);
55 55
         }
56 56
 
57
-        $setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix;
57
+        $setting_name = 'MAJ_MISC_XREF_NEXT_'.$prefix;
58 58
         // Lock the row, so that only one new XREF may be generated at a time.
59 59
         DB::table('gedcom_setting')
60 60
             ->where('gedcom_id', '=', $tree->id())
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 
65 65
         $increment = 1.0;
66 66
         do {
67
-            $num = (int) $tree->getPreference($setting_name) + (int) $increment;
67
+            $num = (int)$tree->getPreference($setting_name) + (int)$increment;
68 68
 
69 69
             // This exponential increment allows us to scan over large blocks of
70 70
             // existing data in a reasonable time.
71 71
             $increment *= 1.01;
72 72
 
73
-            $xref = $prefix . $num . $suffix;
73
+            $xref = $prefix.$num.$suffix;
74 74
 
75 75
             // Records may already exist with this sequence number.
76 76
             $already_used =
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists();
83 83
         } while ($already_used);
84 84
 
85
-        $tree->setPreference($setting_name, (string) $num);
85
+        $tree->setPreference($setting_name, (string)$num);
86 86
 
87 87
         return $xref;
88 88
     }
Please login to merge, or discard this patch.
app/Module/MiscExtensions/Http/RequestHandlers/AdminConfigAction.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -29,54 +29,54 @@
 block discarded – undo
29 29
  */
30 30
 class AdminConfigAction implements RequestHandlerInterface
31 31
 {
32
-    private ?MiscExtensionsModule $module;
32
+	private ?MiscExtensionsModule $module;
33 33
 
34
-    /**
35
-     * Constructor for AdminConfigPage Request Handler
36
-     *
37
-     * @param ModuleService $module_service
38
-     */
39
-    public function __construct(ModuleService $module_service)
40
-    {
41
-        $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first();
42
-    }
34
+	/**
35
+	 * Constructor for AdminConfigPage Request Handler
36
+	 *
37
+	 * @param ModuleService $module_service
38
+	 */
39
+	public function __construct(ModuleService $module_service)
40
+	{
41
+		$this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first();
42
+	}
43 43
 
44
-    /**
45
-     * {@inheritDoc}
46
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
47
-     */
48
-    public function handle(ServerRequestInterface $request): ResponseInterface
49
-    {
50
-        if ($this->module === null) {
51
-            FlashMessages::addMessage(
52
-                I18N::translate('The attached module could not be found.'),
53
-                'danger'
54
-            );
55
-            return Registry::responseFactory()->redirect(AdminConfigPage::class);
56
-        }
44
+	/**
45
+	 * {@inheritDoc}
46
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
47
+	 */
48
+	public function handle(ServerRequestInterface $request): ResponseInterface
49
+	{
50
+		if ($this->module === null) {
51
+			FlashMessages::addMessage(
52
+				I18N::translate('The attached module could not be found.'),
53
+				'danger'
54
+			);
55
+			return Registry::responseFactory()->redirect(AdminConfigPage::class);
56
+		}
57 57
 
58
-        $this->module->setPreference(
59
-            'MAJ_TITLE_PREFIX',
60
-            Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '')
61
-        );
62
-        $this->module->setPreference(
63
-            'MAJ_DISPLAY_CNIL',
64
-            (string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0)
65
-        );
66
-        $this->module->setPreference(
67
-            'MAJ_CNIL_REFERENCE',
68
-            Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '')
69
-        );
70
-        $this->module->setPreference(
71
-            'MAJ_USE_LEGACY_XREF',
72
-            (string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0)
73
-        );
58
+		$this->module->setPreference(
59
+			'MAJ_TITLE_PREFIX',
60
+			Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '')
61
+		);
62
+		$this->module->setPreference(
63
+			'MAJ_DISPLAY_CNIL',
64
+			(string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0)
65
+		);
66
+		$this->module->setPreference(
67
+			'MAJ_CNIL_REFERENCE',
68
+			Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '')
69
+		);
70
+		$this->module->setPreference(
71
+			'MAJ_USE_LEGACY_XREF',
72
+			(string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0)
73
+		);
74 74
 
75
-        FlashMessages::addMessage(
76
-            I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()),
77
-            'success'
78
-        );
75
+		FlashMessages::addMessage(
76
+			I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()),
77
+			'success'
78
+		);
79 79
 
80
-        return Registry::responseFactory()->redirect(AdminConfigPage::class);
81
-    }
80
+		return Registry::responseFactory()->redirect(AdminConfigPage::class);
81
+	}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         );
62 62
         $this->module->setPreference(
63 63
             'MAJ_DISPLAY_CNIL',
64
-            (string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0)
64
+            (string)Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0)
65 65
         );
66 66
         $this->module->setPreference(
67 67
             'MAJ_CNIL_REFERENCE',
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         );
70 70
         $this->module->setPreference(
71 71
             'MAJ_USE_LEGACY_XREF',
72
-            (string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0)
72
+            (string)Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0)
73 73
         );
74 74
 
75 75
         FlashMessages::addMessage(
Please login to merge, or discard this patch.
app/Module/IsSourced/Hooks/IsSourcedStatusHook.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -25,53 +25,53 @@
 block discarded – undo
25 25
  */
26 26
 class IsSourcedStatusHook implements RecordNameTextExtenderInterface
27 27
 {
28
-    private ModuleInterface $module;
29
-    private SourceStatusService $source_status_service;
28
+	private ModuleInterface $module;
29
+	private SourceStatusService $source_status_service;
30 30
 
31
-    /**
32
-     * Constructor for IsSourcedStatusHook
33
-     *
34
-     * @param ModuleInterface $module
35
-     * @param SourceStatusService $source_status_service
36
-     */
37
-    public function __construct(ModuleInterface $module, SourceStatusService $source_status_service)
38
-    {
39
-        $this->module = $module;
40
-        $this->source_status_service = $source_status_service;
41
-    }
31
+	/**
32
+	 * Constructor for IsSourcedStatusHook
33
+	 *
34
+	 * @param ModuleInterface $module
35
+	 * @param SourceStatusService $source_status_service
36
+	 */
37
+	public function __construct(ModuleInterface $module, SourceStatusService $source_status_service)
38
+	{
39
+		$this->module = $module;
40
+		$this->source_status_service = $source_status_service;
41
+	}
42 42
 
43
-    /**
44
-     * {@inheritDoc}
45
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
46
-     */
47
-    public function module(): ModuleInterface
48
-    {
49
-        return $this->module;
50
-    }
43
+	/**
44
+	 * {@inheritDoc}
45
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
46
+	 */
47
+	public function module(): ModuleInterface
48
+	{
49
+		return $this->module;
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritDoc}
54
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
55
-     */
56
-    public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
57
-    {
58
-        return '';
59
-    }
52
+	/**
53
+	 * {@inheritDoc}
54
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
55
+	 */
56
+	public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
57
+	{
58
+		return '';
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritDoc}
63
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
64
-     */
65
-    public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
66
-    {
67
-        if ($use_long && $record instanceof Individual) {
68
-            return view($this->module()->name() . '::hooks/name-append', [
69
-                'module_name'           =>  $this->module()->name(),
70
-                'source_status_service' =>  $this->source_status_service,
71
-                'individual'            =>  $record,
72
-                'size_style'            =>  $size
73
-            ]);
74
-        }
75
-        return '';
76
-    }
61
+	/**
62
+	 * {@inheritDoc}
63
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
64
+	 */
65
+	public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
66
+	{
67
+		if ($use_long && $record instanceof Individual) {
68
+			return view($this->module()->name() . '::hooks/name-append', [
69
+				'module_name'           =>  $this->module()->name(),
70
+				'source_status_service' =>  $this->source_status_service,
71
+				'individual'            =>  $record,
72
+				'size_style'            =>  $size
73
+			]);
74
+		}
75
+		return '';
76
+	}
77 77
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
66 66
     {
67 67
         if ($use_long && $record instanceof Individual) {
68
-            return view($this->module()->name() . '::hooks/name-append', [
68
+            return view($this->module()->name().'::hooks/name-append', [
69 69
                 'module_name'           =>  $this->module()->name(),
70 70
                 'source_status_service' =>  $this->source_status_service,
71 71
                 'individual'            =>  $record,
Please login to merge, or discard this patch.
app/Common/GeoDispersion/Config/NullPlaceMapperConfig.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -26,62 +26,62 @@
 block discarded – undo
26 26
  */
27 27
 class NullPlaceMapperConfig implements PlaceMapperConfigInterface
28 28
 {
29
-    /**
30
-     * {@inheritDoc}
31
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get()
32
-     */
33
-    public function get(string $key, $default = null)
34
-    {
35
-        return $default;
36
-    }
29
+	/**
30
+	 * {@inheritDoc}
31
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get()
32
+	 */
33
+	public function get(string $key, $default = null)
34
+	{
35
+		return $default;
36
+	}
37 37
 
38
-    /**
39
-     * {@inheritDoc}
40
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has()
41
-     */
42
-    public function has(string $key): bool
43
-    {
44
-        return false;
45
-    }
38
+	/**
39
+	 * {@inheritDoc}
40
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has()
41
+	 */
42
+	public function has(string $key): bool
43
+	{
44
+		return false;
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize()
50
-     *
51
-     * @param mixed $config
52
-     * @return $this
53
-     */
54
-    public function jsonDeserialize($config): self
55
-    {
56
-        return $this;
57
-    }
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize()
50
+	 *
51
+	 * @param mixed $config
52
+	 * @return $this
53
+	 */
54
+	public function jsonDeserialize($config): self
55
+	{
56
+		return $this;
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see JsonSerializable::jsonSerialize()
62
-     */
63
-    #[\ReturnTypeWillChange]
64
-    public function jsonSerialize()
65
-    {
66
-        return [];
67
-    }
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see JsonSerializable::jsonSerialize()
62
+	 */
63
+	#[\ReturnTypeWillChange]
64
+	public function jsonSerialize()
65
+	{
66
+		return [];
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritDoc}
71
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent()
72
-     */
73
-    public function configContent(ModuleInterface $module, Tree $tree): string
74
-    {
75
-        return '';
76
-    }
69
+	/**
70
+	 * {@inheritDoc}
71
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent()
72
+	 */
73
+	public function configContent(ModuleInterface $module, Tree $tree): string
74
+	{
75
+		return '';
76
+	}
77 77
 
78
-    /**
79
-     * {@inheritDoc}
80
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate()
81
-     * @return $this
82
-     */
83
-    public function withConfigUpdate(ServerRequestInterface $request): self
84
-    {
85
-        return $this;
86
-    }
78
+	/**
79
+	 * {@inheritDoc}
80
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate()
81
+	 * @return $this
82
+	 */
83
+	public function withConfigUpdate(ServerRequestInterface $request): self
84
+	{
85
+		return $this;
86
+	}
87 87
 }
Please login to merge, or discard this patch.
app/Module/IsSourced/Services/SourceStatusService.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -30,147 +30,147 @@
 block discarded – undo
30 30
  */
31 31
 class SourceStatusService
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
-     * Extract gedcom for all source citations of a fact.
43
-     * Logic removed from \Fisharebest\Webtrees\Fact.
44
-     *
45
-     * @param Fact $fact
46
-     * @return string[]
47
-     */
48
-    private function extractCitations(Fact $fact)
49
-    {
50
-        $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/';
51
-        preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER);
52
-        $citations = [];
53
-        foreach ($matches as $match) {
54
-            $source = Registry::sourceFactory()->make($match[2], $fact->record()->tree());
55
-            if ($source !== null && $source->canShow()) {
56
-                $citations[] = $match[1];
57
-            }
58
-        }
59
-        return $citations;
60
-    }
61
-
62
-    /**
63
-     * Return the status of source citations for a fact.
64
-     *
65
-     * @param Fact $fact
66
-     * @return FactSourceStatus
67
-     */
68
-    public function sourceStatusForFact(Fact $fact): FactSourceStatus
69
-    {
70
-        $source_status = new FactSourceStatus();
71
-
72
-        $date = $fact->date();
73
-        $source_status
74
-            ->setFactHasDate($date->isOK())
75
-            ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay());
76
-
77
-        foreach ($this->extractCitations($fact) as $citation) {
78
-            $source_status
79
-                ->setHasSource(true)
80
-                ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1);
81
-
82
-            preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER);
83
-            foreach ($date_matches as $date_match) {
84
-                $source_date = new Date($date_match[1]);
85
-                $source_status
86
-                    ->addSourceHasDate($source_date->isOK())
87
-                    ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK()
88
-                        && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN);
89
-            }
90
-
91
-            if ($source_status->isFullySourced()) {
92
-                return $source_status;
93
-            }
94
-        }
95
-
96
-        return $source_status;
97
-    }
98
-
99
-    /**
100
-     * Return the status of sources for a Gedcom record.
101
-     *
102
-     * @param GedcomRecord $record
103
-     * @return SourceStatus
104
-     */
105
-    public function sourceStatusForRecord(GedcomRecord $record): SourceStatus
106
-    {
107
-        $source_status = new SourceStatus();
108
-
109
-        foreach ($record->facts(['SOUR']) as $source) {
110
-            $source_status
111
-                ->setHasSource(true)
112
-                ->addHasSupportingDocument($source->attribute('_ACT') !== '');
113
-
114
-            if ($source_status->isFullySourced()) {
115
-                return $source_status;
116
-            }
117
-        }
118
-
119
-        return $source_status;
120
-    }
121
-
122
-    /**
123
-     * Return the status of source citations for a list of fact types associated with a record.
124
-     *
125
-     * @param GedcomRecord $record
126
-     * @param string[] $tags
127
-     * @return FactSourceStatus
128
-     */
129
-    public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus
130
-    {
131
-        $source_status = new NullFactSourceStatus();
132
-
133
-        foreach ($record->facts($tags) as $fact) {
134
-            $source_status = $source_status->combineWith($this->sourceStatusForFact($fact));
135
-            if ($source_status->isFullySourced()) {
136
-                return $source_status;
137
-            }
138
-        }
139
-
140
-        return $source_status;
141
-    }
142
-
143
-    /**
144
-     * Return the status of source citations for an individual's birth events.
145
-     *
146
-     * @param Individual $individual
147
-     * @return FactSourceStatus
148
-     */
149
-    public function sourceStatusForBirth(Individual $individual): FactSourceStatus
150
-    {
151
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
152
-    }
153
-
154
-    /**
155
-     * Return the status of source citations for an individual's death events.
156
-     *
157
-     * @param Individual $individual
158
-     * @return FactSourceStatus
159
-     */
160
-    public function sourceStatusForDeath(Individual $individual): FactSourceStatus
161
-    {
162
-        return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
163
-    }
164
-
165
-    /**
166
-     * Return the status of source citations for a family's marriage events.
167
-     *
168
-     * @param Family $family
169
-     * @return FactSourceStatus
170
-     */
171
-    public function sourceStatusForMarriage(Family $family): FactSourceStatus
172
-    {
173
-        $marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS'];
174
-        return $this->sourceStatusForFactsWithTags($family, $marr_events);
175
-    }
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
+	 * Extract gedcom for all source citations of a fact.
43
+	 * Logic removed from \Fisharebest\Webtrees\Fact.
44
+	 *
45
+	 * @param Fact $fact
46
+	 * @return string[]
47
+	 */
48
+	private function extractCitations(Fact $fact)
49
+	{
50
+		$extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/';
51
+		preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER);
52
+		$citations = [];
53
+		foreach ($matches as $match) {
54
+			$source = Registry::sourceFactory()->make($match[2], $fact->record()->tree());
55
+			if ($source !== null && $source->canShow()) {
56
+				$citations[] = $match[1];
57
+			}
58
+		}
59
+		return $citations;
60
+	}
61
+
62
+	/**
63
+	 * Return the status of source citations for a fact.
64
+	 *
65
+	 * @param Fact $fact
66
+	 * @return FactSourceStatus
67
+	 */
68
+	public function sourceStatusForFact(Fact $fact): FactSourceStatus
69
+	{
70
+		$source_status = new FactSourceStatus();
71
+
72
+		$date = $fact->date();
73
+		$source_status
74
+			->setFactHasDate($date->isOK())
75
+			->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay());
76
+
77
+		foreach ($this->extractCitations($fact) as $citation) {
78
+			$source_status
79
+				->setHasSource(true)
80
+				->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1);
81
+
82
+			preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER);
83
+			foreach ($date_matches as $date_match) {
84
+				$source_date = new Date($date_match[1]);
85
+				$source_status
86
+					->addSourceHasDate($source_date->isOK())
87
+					->addSourceMatchesFactDate($date->isOK() && $source_date->isOK()
88
+						&& abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN);
89
+			}
90
+
91
+			if ($source_status->isFullySourced()) {
92
+				return $source_status;
93
+			}
94
+		}
95
+
96
+		return $source_status;
97
+	}
98
+
99
+	/**
100
+	 * Return the status of sources for a Gedcom record.
101
+	 *
102
+	 * @param GedcomRecord $record
103
+	 * @return SourceStatus
104
+	 */
105
+	public function sourceStatusForRecord(GedcomRecord $record): SourceStatus
106
+	{
107
+		$source_status = new SourceStatus();
108
+
109
+		foreach ($record->facts(['SOUR']) as $source) {
110
+			$source_status
111
+				->setHasSource(true)
112
+				->addHasSupportingDocument($source->attribute('_ACT') !== '');
113
+
114
+			if ($source_status->isFullySourced()) {
115
+				return $source_status;
116
+			}
117
+		}
118
+
119
+		return $source_status;
120
+	}
121
+
122
+	/**
123
+	 * Return the status of source citations for a list of fact types associated with a record.
124
+	 *
125
+	 * @param GedcomRecord $record
126
+	 * @param string[] $tags
127
+	 * @return FactSourceStatus
128
+	 */
129
+	public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus
130
+	{
131
+		$source_status = new NullFactSourceStatus();
132
+
133
+		foreach ($record->facts($tags) as $fact) {
134
+			$source_status = $source_status->combineWith($this->sourceStatusForFact($fact));
135
+			if ($source_status->isFullySourced()) {
136
+				return $source_status;
137
+			}
138
+		}
139
+
140
+		return $source_status;
141
+	}
142
+
143
+	/**
144
+	 * Return the status of source citations for an individual's birth events.
145
+	 *
146
+	 * @param Individual $individual
147
+	 * @return FactSourceStatus
148
+	 */
149
+	public function sourceStatusForBirth(Individual $individual): FactSourceStatus
150
+	{
151
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS);
152
+	}
153
+
154
+	/**
155
+	 * Return the status of source citations for an individual's death events.
156
+	 *
157
+	 * @param Individual $individual
158
+	 * @return FactSourceStatus
159
+	 */
160
+	public function sourceStatusForDeath(Individual $individual): FactSourceStatus
161
+	{
162
+		return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS);
163
+	}
164
+
165
+	/**
166
+	 * Return the status of source citations for a family's marriage events.
167
+	 *
168
+	 * @param Family $family
169
+	 * @return FactSourceStatus
170
+	 */
171
+	public function sourceStatusForMarriage(Family $family): FactSourceStatus
172
+	{
173
+		$marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS'];
174
+		return $this->sourceStatusForFactsWithTags($family, $marr_events);
175
+	}
176 176
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
      */
48 48
     private function extractCitations(Fact $fact)
49 49
     {
50
-        $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/';
50
+        $extract_regex = '/\n(2 SOUR @('.Gedcom::REGEX_XREF.')@(?:\n[3-9] .*)*)/';
51 51
         preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER);
52 52
         $citations = [];
53 53
         foreach ($matches as $match) {
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Model/GeoAnalysisMapAdapter.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -29,191 +29,191 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMapAdapter
31 31
 {
32
-    private int $id;
33
-    private int $view_id;
34
-    private MapDefinitionInterface $map;
35
-    private PlaceMapperInterface $place_mapper;
36
-    private MapViewConfigInterface $config;
37
-
38
-    /**
39
-     * Constructor for GeoAnalysisMapAdapter
40
-     *
41
-     * @param int $id
42
-     * @param MapDefinitionInterface $map
43
-     * @param PlaceMapperInterface $mapper
44
-     * @param MapViewConfigInterface $config
45
-     */
46
-    public function __construct(
47
-        int $id,
48
-        int $view_id,
49
-        MapDefinitionInterface $map,
50
-        PlaceMapperInterface $mapper,
51
-        MapViewConfigInterface $config
52
-    ) {
53
-        $this->id = $id;
54
-        $this->view_id = $view_id;
55
-        $this->map = $map;
56
-        $this->place_mapper = $mapper;
57
-        $this->config = $config;
58
-        $this->place_mapper->setConfig($this->config->mapperConfig());
59
-        $this->place_mapper->setData('map', $map);
60
-        $this->place_mapper->boot();
61
-    }
62
-
63
-    /**
64
-     * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
-     *
66
-     * @param MapDefinitionInterface $map
67
-     * @param PlaceMapperInterface $mapper
68
-     * @param string $mapping_property
69
-     * @return static
70
-     */
71
-    public function with(
72
-        MapDefinitionInterface $map,
73
-        PlaceMapperInterface $mapper,
74
-        string $mapping_property
75
-    ): self {
76
-        $new = clone $this;
77
-        $new->map = $map;
78
-        $new->place_mapper = $mapper;
79
-        $new->config = $this->config->with($mapping_property, $mapper->config());
80
-        return $new;
81
-    }
82
-
83
-    /**
84
-     * Get the GeoAnalysisMapAdapter ID
85
-     *
86
-     * @return int
87
-     */
88
-    public function id(): int
89
-    {
90
-        return $this->id;
91
-    }
92
-
93
-    /**
94
-     * Get the ID of the associated GeoAnalysisView
95
-     *
96
-     * @return int
97
-     */
98
-    public function geoAnalysisViewId(): int
99
-    {
100
-        return $this->view_id;
101
-    }
102
-
103
-    /**
104
-     * Get the associated target map
105
-     *
106
-     * @return MapDefinitionInterface
107
-     */
108
-    public function map(): MapDefinitionInterface
109
-    {
110
-        return $this->map;
111
-    }
112
-
113
-    /**
114
-     * Get the Place Mapper used for the mapping
115
-     *
116
-     * @return PlaceMapperInterface
117
-     */
118
-    public function placeMapper(): PlaceMapperInterface
119
-    {
120
-        return $this->place_mapper;
121
-    }
122
-
123
-    /**
124
-     * Get the configuration of the Map View.
125
-     *
126
-     * @return MapViewConfigInterface
127
-     */
128
-    public function viewConfig(): MapViewConfigInterface
129
-    {
130
-        return $this->config;
131
-    }
132
-
133
-    /**
134
-     * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
-     *
136
-     * @param GeoAnalysisResult $result
137
-     * @return MapAdapterResult
138
-     */
139
-    public function convert(GeoAnalysisResult $result): MapAdapterResult
140
-    {
141
-        $result = $result->copy();
142
-
143
-        $features = [];
144
-        list($features_data, $result) = $this->featureAnalysisData($result);
145
-
146
-        $places_found = $result->countFound();
147
-        foreach ($this->map->features() as $feature) {
148
-            $feature_id = $this->featureId($feature);
149
-            if ($feature_id !== null && $features_data->has($feature_id)) {
150
-                /** @var MapFeatureAnalysisData $feature_data */
151
-                $feature_data = $features_data->get($feature_id)->tagAsExisting();
152
-                $place_count = $feature_data->count();
153
-                $features[] = $feature
154
-                    ->withProperty('count', $place_count)
155
-                    ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
-                    ->withProperty(
157
-                        'places',
158
-                        $feature_data->places()
159
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
-                            ->sort(I18N::comparator())
161
-                            ->toArray()
162
-                    );
163
-            } else {
164
-                $features[] = $feature;
165
-            }
166
-        }
167
-
168
-        $features_data
169
-            ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
-            ->each(
171
-                fn (MapFeatureAnalysisData $data) =>
172
-                    $data->places()->each(
173
-                        function (GeoAnalysisPlace $place) use ($result): void {
174
-                            $result->exclude($place);
175
-                        }
176
-                    )
177
-            );
178
-
179
-        return new MapAdapterResult($result, $features);
180
-    }
181
-
182
-    /**
183
-     * Populate the map features with the mapped Places and total count
184
-     *
185
-     * @param GeoAnalysisResult $result
186
-     * @return mixed[]
187
-     */
188
-    protected function featureAnalysisData(GeoAnalysisResult $result): array
189
-    {
190
-        $features_mapping = new Collection();
191
-
192
-        $byplaces = $result->knownPlaces();
193
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
194
-            $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
195
-
196
-            if ($id !== null && mb_strlen($id) > 0) {
197
-                $features_mapping->put(
198
-                    $id,
199
-                    $features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count())
200
-                );
201
-            } else {
202
-                $result->exclude($item->place());
203
-            }
204
-        });
205
-
206
-        return [ $features_mapping, $result];
207
-    }
208
-
209
-    /**
210
-     * Get the value of the feature property used for the mapping
211
-     *
212
-     * @param Feature $feature
213
-     * @return string|NULL
214
-     */
215
-    protected function featureId(Feature $feature): ?string
216
-    {
217
-        return $feature->getProperty($this->config->mapMappingProperty());
218
-    }
32
+	private int $id;
33
+	private int $view_id;
34
+	private MapDefinitionInterface $map;
35
+	private PlaceMapperInterface $place_mapper;
36
+	private MapViewConfigInterface $config;
37
+
38
+	/**
39
+	 * Constructor for GeoAnalysisMapAdapter
40
+	 *
41
+	 * @param int $id
42
+	 * @param MapDefinitionInterface $map
43
+	 * @param PlaceMapperInterface $mapper
44
+	 * @param MapViewConfigInterface $config
45
+	 */
46
+	public function __construct(
47
+		int $id,
48
+		int $view_id,
49
+		MapDefinitionInterface $map,
50
+		PlaceMapperInterface $mapper,
51
+		MapViewConfigInterface $config
52
+	) {
53
+		$this->id = $id;
54
+		$this->view_id = $view_id;
55
+		$this->map = $map;
56
+		$this->place_mapper = $mapper;
57
+		$this->config = $config;
58
+		$this->place_mapper->setConfig($this->config->mapperConfig());
59
+		$this->place_mapper->setData('map', $map);
60
+		$this->place_mapper->boot();
61
+	}
62
+
63
+	/**
64
+	 * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
+	 *
66
+	 * @param MapDefinitionInterface $map
67
+	 * @param PlaceMapperInterface $mapper
68
+	 * @param string $mapping_property
69
+	 * @return static
70
+	 */
71
+	public function with(
72
+		MapDefinitionInterface $map,
73
+		PlaceMapperInterface $mapper,
74
+		string $mapping_property
75
+	): self {
76
+		$new = clone $this;
77
+		$new->map = $map;
78
+		$new->place_mapper = $mapper;
79
+		$new->config = $this->config->with($mapping_property, $mapper->config());
80
+		return $new;
81
+	}
82
+
83
+	/**
84
+	 * Get the GeoAnalysisMapAdapter ID
85
+	 *
86
+	 * @return int
87
+	 */
88
+	public function id(): int
89
+	{
90
+		return $this->id;
91
+	}
92
+
93
+	/**
94
+	 * Get the ID of the associated GeoAnalysisView
95
+	 *
96
+	 * @return int
97
+	 */
98
+	public function geoAnalysisViewId(): int
99
+	{
100
+		return $this->view_id;
101
+	}
102
+
103
+	/**
104
+	 * Get the associated target map
105
+	 *
106
+	 * @return MapDefinitionInterface
107
+	 */
108
+	public function map(): MapDefinitionInterface
109
+	{
110
+		return $this->map;
111
+	}
112
+
113
+	/**
114
+	 * Get the Place Mapper used for the mapping
115
+	 *
116
+	 * @return PlaceMapperInterface
117
+	 */
118
+	public function placeMapper(): PlaceMapperInterface
119
+	{
120
+		return $this->place_mapper;
121
+	}
122
+
123
+	/**
124
+	 * Get the configuration of the Map View.
125
+	 *
126
+	 * @return MapViewConfigInterface
127
+	 */
128
+	public function viewConfig(): MapViewConfigInterface
129
+	{
130
+		return $this->config;
131
+	}
132
+
133
+	/**
134
+	 * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
+	 *
136
+	 * @param GeoAnalysisResult $result
137
+	 * @return MapAdapterResult
138
+	 */
139
+	public function convert(GeoAnalysisResult $result): MapAdapterResult
140
+	{
141
+		$result = $result->copy();
142
+
143
+		$features = [];
144
+		list($features_data, $result) = $this->featureAnalysisData($result);
145
+
146
+		$places_found = $result->countFound();
147
+		foreach ($this->map->features() as $feature) {
148
+			$feature_id = $this->featureId($feature);
149
+			if ($feature_id !== null && $features_data->has($feature_id)) {
150
+				/** @var MapFeatureAnalysisData $feature_data */
151
+				$feature_data = $features_data->get($feature_id)->tagAsExisting();
152
+				$place_count = $feature_data->count();
153
+				$features[] = $feature
154
+					->withProperty('count', $place_count)
155
+					->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
+					->withProperty(
157
+						'places',
158
+						$feature_data->places()
159
+							->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
+							->sort(I18N::comparator())
161
+							->toArray()
162
+					);
163
+			} else {
164
+				$features[] = $feature;
165
+			}
166
+		}
167
+
168
+		$features_data
169
+			->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
+			->each(
171
+				fn (MapFeatureAnalysisData $data) =>
172
+					$data->places()->each(
173
+						function (GeoAnalysisPlace $place) use ($result): void {
174
+							$result->exclude($place);
175
+						}
176
+					)
177
+			);
178
+
179
+		return new MapAdapterResult($result, $features);
180
+	}
181
+
182
+	/**
183
+	 * Populate the map features with the mapped Places and total count
184
+	 *
185
+	 * @param GeoAnalysisResult $result
186
+	 * @return mixed[]
187
+	 */
188
+	protected function featureAnalysisData(GeoAnalysisResult $result): array
189
+	{
190
+		$features_mapping = new Collection();
191
+
192
+		$byplaces = $result->knownPlaces();
193
+		$byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
194
+			$id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
195
+
196
+			if ($id !== null && mb_strlen($id) > 0) {
197
+				$features_mapping->put(
198
+					$id,
199
+					$features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count())
200
+				);
201
+			} else {
202
+				$result->exclude($item->place());
203
+			}
204
+		});
205
+
206
+		return [ $features_mapping, $result];
207
+	}
208
+
209
+	/**
210
+	 * Get the value of the feature property used for the mapping
211
+	 *
212
+	 * @param Feature $feature
213
+	 * @return string|NULL
214
+	 */
215
+	protected function featureId(Feature $feature): ?string
216
+	{
217
+		return $feature->getProperty($this->config->mapMappingProperty());
218
+	}
219 219
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                     ->withProperty(
157 157
                         'places',
158 158
                         $feature_data->places()
159
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
159
+                            ->map(fn(GeoAnalysisPlace $place) : string => $place->place()->firstParts(1)->first())
160 160
                             ->sort(I18N::comparator())
161 161
                             ->toArray()
162 162
                     );
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             ->each(
171 171
                 fn (MapFeatureAnalysisData $data) =>
172 172
                     $data->places()->each(
173
-                        function (GeoAnalysisPlace $place) use ($result): void {
173
+                        function(GeoAnalysisPlace $place) use ($result): void {
174 174
                             $result->exclude($place);
175 175
                         }
176 176
                     )
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $features_mapping = new Collection();
191 191
 
192 192
         $byplaces = $result->knownPlaces();
193
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
193
+        $byplaces->each(function(GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
194 194
             $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
195 195
 
196 196
             if ($id !== null && mb_strlen($id) > 0) {
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
             }
204 204
         });
205 205
 
206
-        return [ $features_mapping, $result];
206
+        return [$features_mapping, $result];
207 207
     }
208 208
 
209 209
     /**
Please login to merge, or discard this patch.