Issues (45)

src/Socializer.php (1 issue)

Labels
1
<?php
2
/**
3
 * Socializer plugin for Craft CMS 3.x
4
 *
5
 * @dedicado Al amor de mi vida, mi Sara **).
6
 * @link      https://enupal.com/
7
 * @copyright Copyright (c) 2019 Enupal LLC
8
 */
9
10
namespace enupal\socializer;
11
12
use Craft;
13
use craft\base\Plugin;
14
15
use craft\events\RegisterUrlRulesEvent;
16
use craft\web\twig\variables\CraftVariable;
17
use craft\web\UrlManager;
18
use enupal\socializer\models\Settings;
19
use enupal\socializer\services\App;
20
use enupal\socializer\variables\SocializerVariable;
21
use yii\base\Event;
22
use craft\services\Gc;
23
24
class Socializer extends Plugin
25
{
26
    /**
27
     * Enable use of Socializer::$app-> in place of Craft::$app->
28
     *
29
     * @var App
30
     */
31
    public static $app;
32
33
    /**
34
     * @var string
35
     */
36
    public string $schemaVersion = '2.0.0';
37
38
    public bool $hasCpSection = true;
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public bool $hasCpSettings = true;
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function init()
49
    {
50
        parent::init();
51
        self::$app = $this->get('app');
52
53
        Event::on(
54
            CraftVariable::class,
55
            CraftVariable::EVENT_INIT,
56
            function(Event $event) {
57
                /** @var CraftVariable $variable */
58
                $variable = $event->sender;
59
                $variable->set('socializer', SocializerVariable::class);
60
            }
61
        );
62
63
        Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) {
64
            $event->rules = array_merge($event->rules, $this->getCpUrlRules());
65
        }
66
        );
67
68
        Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, function(RegisterUrlRulesEvent $event) {
69
            $event->rules = array_merge($event->rules, $this->getSiteUrlRules());
70
        }
71
        );
72
73
        Event::on(Gc::class, Gc::EVENT_RUN, function() {
74
            Craft::$app->gc->hardDelete('{{%enupalsocializer_providers}}');
0 ignored issues
show
The method hardDelete() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
            Craft::$app->gc->/** @scrutinizer ignore-call */ 
75
                             hardDelete('{{%enupalsocializer_providers}}');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
        });
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    private function getCpUrlRules()
82
    {
83
        return [
84
            'enupal-socializer/providers/new' =>
85
                'enupal-socializer/providers/edit-provider',
86
87
            'enupal-socializer/providers/edit/<providerId:\d+>' =>
88
                'enupal-socializer/providers/edit-provider'
89
        ];
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function getCpNavItem(): ?array
96
    {
97
        $parent = parent::getCpNavItem();
98
        return array_merge($parent, [
99
            'subnav' => [
100
                'providers' => [
101
                    "label" => Craft::t('enupal-socializer',"Providers"),
102
                    "url" => 'enupal-socializer/providers'
103
                ],
104
                'settings' => [
105
                    "label" => Craft::t('enupal-socializer',"Settings"),
106
                    "url" => 'enupal-socializer/settings'
107
                ]
108
            ]
109
        ]);
110
    }
111
112
    /**
113
     * @return array
114
     */
115
    private function getSiteUrlRules()
116
    {
117
        return [
118
            'socializer/login' =>
119
                'enupal-socializer/login/login',
120
121
            'socializer/login/callback' =>
122
                'enupal-socializer/login/callback'
123
        ];
124
    }
125
126
    protected function settingsHtml(): ?string
127
    {
128
        return Craft::$app->getView()->renderTemplate('enupal-socializer/settings/index');
129
    }
130
131
    /**
132
     * @inheritdoc
133
     */
134
    protected function createSettingsModel(): ?\craft\base\Model
135
    {
136
        return new Settings();
137
    }
138
}
139