DeleteModulePreferences::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php namespace Anomaly\PreferencesModule\Preference\Listener;
2
3
use Anomaly\PreferencesModule\Preference\Contract\PreferenceRepositoryInterface;
4
use Anomaly\Streams\Platform\Addon\Module\Event\ModuleWasUninstalled;
5
6
/**
7
 * Class DeleteModulePreferences
8
 *
9
 * @link          http://pyrocms.com/
10
 * @author        PyroCMS, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 */
13
class DeleteModulePreferences
14
{
15
16
    /**
17
     * The settings repository.
18
     *
19
     * @var PreferenceRepositoryInterface
20
     */
21
    protected $settings;
22
23
    /**
24
     * Create a new DeleteModulePreferences instance.
25
     *
26
     * @param PreferenceRepositoryInterface $settings
27
     */
28
    public function __construct(PreferenceRepositoryInterface $settings)
29
    {
30
        $this->settings = $settings;
31
    }
32
33
    /**
34
     * Handle the event.
35
     *
36
     * @param ModuleWasUninstalled $event
37
     */
38
    public function handle(ModuleWasUninstalled $event)
39
    {
40
        $module = $event->getModule();
41
42
        foreach ($this->settings->findAllByNamespace($module->getNamespace()) as $setting) {
43
            $this->settings->delete($setting);
44
        }
45
    }
46
}
47