Completed
Push — master ( d98408...140c7d )
by Marc
03:08
created
src/Commands/ListNotifications.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
         $hosts = $this->determineHostModelClass()::all();
35 35
         if ($hostName = $this->option('host')) {
36
-            $hosts = $hosts->filter(function (Host $host) use ($hostName) {
36
+            $hosts = $hosts->filter(function(Host $host) use ($hostName) {
37 37
                 return $host->name === $hostName;
38 38
             });
39 39
         }
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
         $rows = [];
51 51
         $first = true;
52 52
         foreach ($hosts as $host) {
53
-            if(!$first) {
53
+            if (!$first) {
54 54
                 $rows[] = new TableSeparator();
55 55
             }
56 56
             /* @var $host Host */
57 57
             $rows[] = [$host->name];
58 58
 
59 59
             $hostNotifications = $host->getCustomProperty('notifications');
60
-            if($hostNotifications) {
60
+            if ($hostNotifications) {
61 61
                 $rows = $this->displayCustomNotification($hostNotifications, $rows);
62 62
             }
63 63
             else {
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
             $rows[] = [''];
74 74
             $temp = [implode("\n", str_split($notification, 50))];
75 75
             foreach ($this->channels as $type => $channel) {
76
-                if(isset($hostNotifications[$notification]) && array_search($type, $hostNotifications[$notification]['channels']) !== false) {
77
-                    if(isset($hostNotifications['configuration'][$type])) {
76
+                if (isset($hostNotifications[$notification]) && array_search($type, $hostNotifications[$notification]['channels']) !== false) {
77
+                    if (isset($hostNotifications['configuration'][$type])) {
78 78
                         $configurationList = [];
79 79
                         foreach ($hostNotifications['configuration'][$type] as $configurationAttribut => $configurationValue) {
80
-                            $configurationList[] = $configurationAttribut.':'.(is_array($configurationValue)?implode(',', $configurationValue):$configurationValue);
80
+                            $configurationList[] = $configurationAttribut.':'.(is_array($configurationValue) ?implode(',', $configurationValue) : $configurationValue);
81 81
                         }
82 82
                         $temp[] = implode("\n", $configurationList);
83 83
                     }
Please login to merge, or discard this patch.
src/ServerMonitorPluginNotificationByHostServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     {
14 14
         if ($this->app->runningInConsole()) {
15 15
             $this->publishes([
16
-                __DIR__ . '/../config/server-monitor-plugin-notification-by-host.php' => config_path('server-monitor-plugin-notification-by-host.php'),
16
+                __DIR__.'/../config/server-monitor-plugin-notification-by-host.php' => config_path('server-monitor-plugin-notification-by-host.php'),
17 17
             ], 'config');
18 18
 
19 19
         }
Please login to merge, or discard this patch.
src/Notifications/Notifiable.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
 
6 6
 class Notifiable extends \Spatie\ServerMonitor\Notifications\Notifiable
7 7
 {
8
-    public function routeNotificationForMail(): ?array
8
+    public function routeNotificationForMail(): ? array
9 9
     {
10
-        if($notification = $this->getSpecificConfiguration('mail')) {
10
+        if ($notification = $this->getSpecificConfiguration('mail')) {
11 11
             return $notification;
12 12
         }
13 13
         return parent::routeNotificationForMail();
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
     public function routeNotificationForSlack(): ?string
17 17
     {
18
-        if($notification = $this->getSpecificConfiguration('slack')) {
18
+        if ($notification = $this->getSpecificConfiguration('slack')) {
19 19
             return $notification;
20 20
         }
21 21
         return parent::routeNotificationForSlack();
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
 
31 31
     private function getSpecificConfiguration($type) {
32 32
         $notifications = $this->getHost()->getCustomProperty('notifications');
33
-        if($notifications) {
34
-            if(!isset($notifications['configuration'][$type])) {
33
+        if ($notifications) {
34
+            if (!isset($notifications['configuration'][$type])) {
35 35
                 return null;
36 36
             }
37
-            if(count($notifications['configuration'][$type]) == 1) {
37
+            if (count($notifications['configuration'][$type]) == 1) {
38 38
                 $configuration = config('server-monitor-plugin-notification-by-host.notifications.channels.'.$type);
39 39
                 return $notifications['configuration'][$type][array_keys($configuration)[0]];
40 40
             }
Please login to merge, or discard this patch.
src/Commands/AddNotificationByHost.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
         $configure = [];
38 38
         foreach ($notifications as $channel) {
39 39
             $attributes = config('server-monitor-plugin-notification-by-host.notifications.channels.'.$channel);
40
-            if($attributes) {
40
+            if ($attributes) {
41 41
                 foreach ($attributes as $attribute => $type) {
42
-                    $configure[$channel][$attribute] = $this->ask("For channel `$channel` attribute `$attribute`?".($type == 'array'?" (values separate by ,)":""), false);
43
-                    if($type == 'array') {
42
+                    $configure[$channel][$attribute] = $this->ask("For channel `$channel` attribute `$attribute`?".($type == 'array' ? " (values separate by ,)" : ""), false);
43
+                    if ($type == 'array') {
44 44
                         $configure[$channel][$attribute] = explode(',', $configure[$channel][$attribute]);
45 45
                     }
46
-                    if(!$configure[$channel][$attribute]) {
46
+                    if (!$configure[$channel][$attribute]) {
47 47
                         unset($configure[$channel][$attribute]);
48 48
                     }
49 49
                 }
50
-                if(!$configure[$channel]) {
50
+                if (!$configure[$channel]) {
51 51
                     unset($configure[$channel]);
52 52
                 }
53 53
             }
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
                 : $this->choice('Which host?', $hostList);
69 69
 
70 70
             $host = $this->determineHostModelClass()::where('name', $hostName)->first();
71
-            if(!$host) {
71
+            if (!$host) {
72 72
                 $this->warn("This host `{$hostName}` doesn't exist");
73 73
             }
74
-        } while(!$host);
74
+        } while (!$host);
75 75
 
76 76
         $this->info("Host: {$host->name}");
77 77
         return $host;
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
             $notifications[] = $channel;
86 86
         }
87 87
         $notificationsParameters = [];
88
-        foreach(config('server-monitor.notifications.notifications') as $class => $notification) {
88
+        foreach (config('server-monitor.notifications.notifications') as $class => $notification) {
89 89
             $this->line("Notification for ".$class);
90 90
 
91 91
             $channels = $this->choice('Which channel? (values separate by ,)', $notifications, 0, null, true);
92
-            if($channels[0] != 'No channel') {
92
+            if ($channels[0] != 'No channel') {
93 93
                 $notificationsParameters[$class]['channels'] = $channels;
94 94
             }
95 95
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     }
98 98
 
99 99
     private function configuration($host, $notificationsParameters) {
100
-        if(!$notificationsParameters) {
100
+        if (!$notificationsParameters) {
101 101
             $this->warn("The host {$host->name} has no notification configure !");
102 102
         }
103 103
         else {
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 
109 109
             $notificationsUsed = [];
110 110
             foreach ($notificationsParameters as $check) {
111
-                if(isset($check['channels']) && $check['channels']) {
111
+                if (isset($check['channels']) && $check['channels']) {
112 112
                     $notificationsUsed = array_unique(array_merge($notificationsUsed, $check['channels']), SORT_REGULAR);
113 113
                 }
114 114
             }
115 115
 
116
-            if($notificationsUsed) {
116
+            if ($notificationsUsed) {
117 117
                 $configure = $this->askConfiguration($notificationsUsed);
118 118
                 $notificationsParameters['configuration'] = $configure;
119 119
             }
Please login to merge, or discard this patch.
tests/Notifications/NotifiableTest.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             'port' => 22,
30 30
         ]);
31 31
 
32
-        $host->checks()->saveMany(collect($checks)->map(function (string $checkName) {
32
+        $host->checks()->saveMany(collect($checks)->map(function(string $checkName) {
33 33
             return new Check([
34 34
                 'type' => $checkName,
35 35
                 'status' => CheckStatus::NOT_YET_CHECKED,
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
     function route_notification_for_mail_custom() {
51 51
         /* @var $host Host */
52 52
         $host = $this->notifiable->getEvent()->check->host()->first();
53
-        $notifications =  [
53
+        $notifications = [
54 54
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
55 55
                 [
56 56
                     'channels' => ['mail']
57 57
                 ],
58
-            'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]]
58
+            'configuration' => ['mail' => ['to' => ['[email protected]']]]
59 59
         ];
60 60
 
61 61
         $host->setCustomProperty('notifications', $notifications);
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
     function route_notification_no_custom_data() {
71 71
         /* @var $host Host */
72 72
         $host = $this->notifiable->getEvent()->check->host()->first();
73
-        $notifications =  [
73
+        $notifications = [
74 74
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' =>
75 75
                 [
76 76
                     'channels' => ['slack']
77 77
                 ],
78
-            'configuration' => ['slack' => [ 'webhook' => ['urlSlack'] ]]
78
+            'configuration' => ['slack' => ['webhook' => ['urlSlack']]]
79 79
         ];
80 80
 
81 81
         $host->setCustomProperty('notifications', $notifications);
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
     function route_notification_for_mail_custom_array() {
91 91
         /* @var $host Host */
92 92
         $host = $this->notifiable->getEvent()->check->host()->first();
93
-        $notifications =  [
93
+        $notifications = [
94 94
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
95 95
                 [
96 96
                     'channels' => ['mail']
97 97
                 ],
98
-            'configuration' => ['mail' => [ 'to' => ['[email protected]'], 'other' => 'otherData']]
98
+            'configuration' => ['mail' => ['to' => ['[email protected]'], 'other' => 'otherData']]
99 99
         ];
100 100
 
101 101
         $host->setCustomProperty('notifications', $notifications);
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
     function route_notification_for_slack_custom() {
119 119
         /* @var $host Host */
120 120
         $host = $this->notifiable->getEvent()->check->host()->first();
121
-        $notifications =  [
121
+        $notifications = [
122 122
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
123 123
                 [
124 124
                     'channels' => ['slack']
125 125
                 ],
126
-            'configuration' => ['slack' => [ 'webhook_url' => 'urlSlack' ]]
126
+            'configuration' => ['slack' => ['webhook_url' => 'urlSlack']]
127 127
         ];
128 128
 
129 129
         $host->setCustomProperty('notifications', $notifications);
Please login to merge, or discard this patch.
tests/Notifications/BaseNotificationTraitTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
             'port' => 22,
34 34
         ]);
35 35
 
36
-        $host->checks()->saveMany(collect($checks)->map(function (string $checkName) {
36
+        $host->checks()->saveMany(collect($checks)->map(function(string $checkName) {
37 37
             return new Check([
38 38
                 'type' => $checkName,
39 39
                 'status' => CheckStatus::NOT_YET_CHECKED,
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             'port' => 22,
59 59
         ]);
60 60
 
61
-        $host->checks()->saveMany(collect($checks)->map(function (string $checkName) {
61
+        $host->checks()->saveMany(collect($checks)->map(function(string $checkName) {
62 62
             return new Check([
63 63
                 'type' => $checkName,
64 64
                 'status' => CheckStatus::NOT_YET_CHECKED,
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
         $this->notifiable->setEvent($event);
70 70
 
71 71
         $host = $this->notifiable->getEvent()->check->host()->first();
72
-        $notifications =  [
72
+        $notifications = [
73 73
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
74 74
                 [
75 75
                     'channels' => ['mail']
76 76
                 ],
77
-            'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]]
77
+            'configuration' => ['mail' => ['to' => ['[email protected]']]]
78 78
         ];
79 79
 
80 80
         $host->setCustomProperty('notifications', $notifications);
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             'port' => 22,
97 97
         ]);
98 98
 
99
-        $host->checks()->saveMany(collect($checks)->map(function (string $checkName) {
99
+        $host->checks()->saveMany(collect($checks)->map(function(string $checkName) {
100 100
             return new Check([
101 101
                 'type' => $checkName,
102 102
                 'status' => CheckStatus::NOT_YET_CHECKED,
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
         $this->notifiable->setEvent($event);
108 108
 
109 109
         $host = $this->notifiable->getEvent()->check->host()->first();
110
-        $notifications =  [
110
+        $notifications = [
111 111
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' =>
112 112
                 [
113 113
                     'channels' => ['mail']
114 114
                 ],
115
-            'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]]
115
+            'configuration' => ['mail' => ['to' => ['[email protected]']]]
116 116
         ];
117 117
 
118 118
         $host->setCustomProperty('notifications', $notifications);
Please login to merge, or discard this patch.
tests/TestCase.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         ]);
54 54
 
55 55
         /* @var $app['config'] Repository */
56
-        $app['config']->set(['server-monitor' => include(__DIR__ . '/../vendor/spatie/laravel-server-monitor/config/server-monitor.php')]);
56
+        $app['config']->set(['server-monitor' => include(__DIR__.'/../vendor/spatie/laravel-server-monitor/config/server-monitor.php')]);
57 57
 
58 58
         $app['config']->set('server-monitor.notifications.notifications', [
59 59
             \TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded::class => [],
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         $app['config']->set('server-monitor.notifications.slack', ['webhook_url' => 'test']);
67 67
         $app['config']->set('server-monitor.notifications.notifiable', TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifiable::class);
68 68
 
69
-        $app['config']->set(['server-monitor-plugin-notification-by-host' => include(__DIR__ . '/../config/server-monitor-plugin-notification-by-host.php')]);
69
+        $app['config']->set(['server-monitor-plugin-notification-by-host' => include(__DIR__.'/../config/server-monitor-plugin-notification-by-host.php')]);
70 70
 
71 71
         $this->setUpDatabase();
72 72
     }
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     protected function seeInConsoleOutput($searchStrings)
88 88
     {
89
-        if (! is_array($searchStrings)) {
89
+        if (!is_array($searchStrings)) {
90 90
             $searchStrings = [$searchStrings];
91 91
         }
92 92
         $output = $this->getArtisanOutput();
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     protected function dontSeeInConsoleOutput($searchStrings)
102 102
     {
103
-        if (! is_array($searchStrings)) {
103
+        if (!is_array($searchStrings)) {
104 104
             $searchStrings = [$searchStrings];
105 105
         }
106 106
         $output = $this->getArtisanOutput();
Please login to merge, or discard this patch.
tests/Commands/ListNotificationsTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
             }
29 29
 
30 30
             public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null) {
31
-                echo $question . "\n";
31
+                echo $question."\n";
32 32
                 $result = $this->answers[$this->answer];
33 33
                 if ($multiple) {
34 34
                     if (!is_array($this->answers[$this->answer])) {
@@ -40,17 +40,17 @@  discard block
 block discarded – undo
40 40
             }
41 41
 
42 42
             public function confirm($question, $default = false) {
43
-                echo $question . "\n";
43
+                echo $question."\n";
44 44
                 return $this->answers[$this->answer++];
45 45
             }
46 46
 
47 47
             public function ask($question, $default = null) {
48
-                echo $question . "\n";
48
+                echo $question."\n";
49 49
                 return $this->answers[$this->answer++];
50 50
             }
51 51
         };
52 52
 
53
-        $this->app->bind('command.server-monitor:list-notifications', function () {
53
+        $this->app->bind('command.server-monitor:list-notifications', function() {
54 54
             return $this->command;
55 55
         });
56 56
     }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     /** @test */
71 71
     public function it_check() {
72 72
 
73
-        $notifications =  [
73
+        $notifications = [
74 74
             'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
75 75
                 [
76 76
                     'channels' => ['mail']
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                 [
80 80
                     'channels' => ['slack']
81 81
                 ],
82
-            'configuration' => ['mail' => [ 'to' => '[email protected]' ]]
82
+            'configuration' => ['mail' => ['to' => '[email protected]']]
83 83
             ];
84 84
 
85 85
         $host = Host::create([
Please login to merge, or discard this patch.
tests/Commands/AddNotificationByHostTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,25 +27,25 @@
 block discarded – undo
27 27
             public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
28 28
             {
29 29
                 $result = $this->answers[$this->answer];
30
-                if($multiple) {
31
-                    if(!is_array($this->answers[$this->answer])) {
30
+                if ($multiple) {
31
+                    if (!is_array($this->answers[$this->answer])) {
32 32
                         $result = [$this->answers[$this->answer]];
33 33
                     }
34 34
                 }
35
-                $this->answer ++;
35
+                $this->answer++;
36 36
                 return $result;
37 37
             }
38 38
             public function confirm($question, $default = false)
39 39
             {
40
-                return $this->answers[$this->answer ++];
40
+                return $this->answers[$this->answer++];
41 41
             }
42 42
 
43 43
             public function ask($question, $default = null) {
44
-                return $this->answers[$this->answer ++];
44
+                return $this->answers[$this->answer++];
45 45
             }
46 46
         };
47 47
 
48
-        $this->app->bind('command.server-monitor:add-notification-host', function () {
48
+        $this->app->bind('command.server-monitor:add-notification-host', function() {
49 49
             return $this->command;
50 50
         });
51 51
     }
Please login to merge, or discard this patch.