Completed
Pull Request — master (#4)
by
unknown
07:52
created
database/migrations/2017_05_01_015818_create_quotalog_table.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@
 block discarded – undo
30 30
      */
31 31
     public function up()
32 32
     {
33
-        Schema::create('quotalog', function (Blueprint $table) {
33
+        Schema::create('quotalog', function(Blueprint $table) {
34 34
             $table->increments('id');
35 35
             $table->date('date');
36
-            $table->string('connection');   //@See config/quota.php
36
+            $table->string('connection'); //@See config/quota.php
37 37
             $table->integer('hits')->default(0);
38 38
             $table->integer('misses')->default(0);
39 39
 
Please login to merge, or discard this patch.
config/quota.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
         'bandwidth' => [
37 37
             'limit' => env('QUOTA_BANDWIDTH_LIMIT', 60),
38
-            'period' => env('QUOTA_BANDWIDTH_PERIOD','second'),
38
+            'period' => env('QUOTA_BANDWIDTH_PERIOD', 'second'),
39 39
             'driver' => 'quota.storage.file',
40 40
             'path' => env('QUOTA_BANDWIDTH_PATH', '/tmp/bandwidth.quota'),
41 41
             'capacity' => env('QUOTA_BANDWIDTH_CAPACITY', 60),
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
         'daily' => [
46 46
             'limit' => env('QUOTA_DAILY_LIMIT', 2500),
47
-            'period' => env('QUOTA_DAILY_PERIOD','day'),
47
+            'period' => env('QUOTA_DAILY_PERIOD', 'day'),
48 48
             'log_table' => env('QUOTA_DAILY_LOG_TABLE', 'quotalog'),
49 49
             'timezone' => env('QUOTA_DAILY_TIMEZONE', 'America/New_York'),
50 50
         ],
Please login to merge, or discard this patch.
src/Contracts/Quota.php 1 patch
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -18,6 +18,7 @@
 block discarded – undo
18 18
 {
19 19
     /**
20 20
      * Enforce a quota.
21
+     * @return boolean
21 22
      */
22 23
     public function enforce();
23 24
 }
Please login to merge, or discard this patch.
src/Quota.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -99,12 +99,12 @@
 block discarded – undo
99 99
         return $result;
100 100
     }
101 101
 
102
-   /**
103
-    * Public interface.
104
-    *
105
-    * NOTE: this class and method are really abstract,
106
-    * but we leave it instantiable for easier testing.
107
-    */
102
+    /**
103
+     * Public interface.
104
+     *
105
+     * NOTE: this class and method are really abstract,
106
+     * but we leave it instantiable for easier testing.
107
+     */
108 108
     public function enforce()
109 109
     {
110 110
         //Override this in descendants.
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
     public function __construct($connection)
61 61
     {
62 62
         $this->connection = $connection;
63
-        $this->index = 'quota.connections.' . $connection;
63
+        $this->index = 'quota.connections.'.$connection;
64 64
 
65
-        $this->limit = config($this->index . '.limit');
65
+        $this->limit = config($this->index.'.limit');
66 66
 
67
-        $period = config($this->index . '.period');
67
+        $period = config($this->index.'.period');
68 68
         $this->setPeriod($period);
69 69
     }
70 70
 
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
      */
195 195
     public function setPeriod($period)
196 196
     {
197
-        if (! $this->validatePeriod($period)) {
197
+        if (!$this->validatePeriod($period)) {
198 198
             $expected = $this->validPeriods();
199 199
 
200 200
             throw new \InvalidArgumentException(
201 201
                 __CLASS__.'::'.__FUNCTION__.
202
-                ' Invalid period: ' . $period .
203
-                ' in connection configuration: ' . $this->connection .
204
-                ' expected one of: ' . PHP_EOL . print_r($expected, 1)
202
+                ' Invalid period: '.$period.
203
+                ' in connection configuration: '.$this->connection.
204
+                ' expected one of: '.PHP_EOL.print_r($expected, 1)
205 205
             );
206 206
         }
207 207
 
Please login to merge, or discard this patch.
src/BandwidthQuota.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
     {
88 88
         parent::__construct($connection);
89 89
 
90
-        $this->driver = config($this->index . '.driver');
90
+        $this->driver = config($this->index.'.driver');
91 91
 
92 92
         //TODO: REFACTOR for multiple storage types.
93 93
         if ($this->driver != 'quota.storage.file') {
94
-            throw new \Exception('Driver: ' . $this->driver . ' not supported.');
94
+            throw new \Exception('Driver: '.$this->driver.' not supported.');
95 95
         }
96 96
 
97
-        $this->path = config($this->index . '.path');
97
+        $this->path = config($this->index.'.path');
98 98
         $this->storage = app($this->driver, ['path' =>  $this->path]);
99 99
         //END REFACTOR
100 100
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
         );
106 106
 
107 107
         //Resolve bucket via IoC container.
108
-        $capacity = config($this->index . '.capacity');
108
+        $capacity = config($this->index.'.capacity');
109 109
         $this->bucket = app('quota.bucket', [
110 110
             'capacity' => $capacity,
111 111
             'rate' => $this->rate,
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $this->bucket->bootstrap($capacity);
117 117
 
118 118
         //Optionally enclose bucket within a blocking consumer.
119
-        if (config($this->index . '.block') == true) {
119
+        if (config($this->index.'.block') == true) {
120 120
             $this->blocker = app('quota.blocker', ['bucket' => $this->bucket]);
121 121
         }
122 122
     }
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
     public function consume($tokens = 1)
178 178
     {
179 179
         if (isset($this->bucket)) {
180
-            if (! isset($this->blocker)) {
180
+            if (!isset($this->blocker)) {
181 181
                 $result = $this->bucket->consume($tokens, $seconds);
182 182
                 if ($result === false) {
183 183
                     throw new \ErrorException(
184
-                        __CLASS__ . '::' . __FUNCTION__ .
185
-                        ' Overquota. Exceeded bandwidth. Wait ' . $seconds . ' seconds.'
184
+                        __CLASS__.'::'.__FUNCTION__.
185
+                        ' Overquota. Exceeded bandwidth. Wait '.$seconds.' seconds.'
186 186
                     );
187 187
                 }
188 188
             } else {
Please login to merge, or discard this patch.
src/QuotaServiceProvider.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
         }
88 88
     }
89 89
 
90
-     /**
91
-     * Register a database migration path.
92
-     *
93
-     * NOTE: This function is already part of 5.4
94
-     * it is backported here for 5.2
95
-     *
96
-     * @param  array|string  $paths
97
-     * @return void
98
-     */
90
+        /**
91
+         * Register a database migration path.
92
+         *
93
+         * NOTE: This function is already part of 5.4
94
+         * it is backported here for 5.2
95
+         *
96
+         * @param  array|string  $paths
97
+         * @return void
98
+         */
99 99
     //protected function loadMigrationsFrom($paths)
100 100
     //{
101 101
     //    dump(__CLASS__.'::'.__FUNCTION__);
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
     public function bindInterfaces()
147 147
     {
148 148
         $this->app->when(RateFactory::class)
149
-          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
150
-          ->give(RateData::class);
149
+            ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
150
+            ->give(RateData::class);
151 151
 
152 152
         $this->app->when(FileStorageFactory::class)
153
-          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
154
-          ->give(FileStorageData::class);
153
+            ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
154
+            ->give(FileStorageData::class);
155 155
 
156 156
         $this->app->when(TokenBucketFactory::class)
157
-          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
158
-          ->give(TokenBucketData::class);
157
+            ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
158
+            ->give(TokenBucketData::class);
159 159
 
160 160
         $this->app->when(BlockingConsumerFactory::class)
161
-          ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
162
-          ->give(BlockingConsumerData::class);
161
+            ->needs('Projectmentor\Quota\Contracts\PayloadInterface')
162
+            ->give(BlockingConsumerData::class);
163 163
     }
164 164
 
165 165
     /**
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
      */
169 169
     protected function registerFactories()
170 170
     {
171
-        $this->app->singleton('quota.factory.rate', function ($app) {
171
+        $this->app->singleton('quota.factory.rate', function($app) {
172 172
             return new RateFactory;
173 173
         });
174 174
 
175
-        $this->app->singleton('quota.factory.storage.file', function ($app) {
175
+        $this->app->singleton('quota.factory.storage.file', function($app) {
176 176
             return new FileStorageFactory;
177 177
         });
178 178
 
179
-        $this->app->singleton('quota.factory.tokenbucket', function ($app) {
179
+        $this->app->singleton('quota.factory.tokenbucket', function($app) {
180 180
             return new TokenBucketFactory;
181 181
         });
182 182
 
183
-        $this->app->singleton('quota.factory.blockingconsumer', function ($app) {
183
+        $this->app->singleton('quota.factory.blockingconsumer', function($app) {
184 184
             return new BlockingConsumerFactory;
185 185
         });
186 186
 
@@ -208,19 +208,19 @@  discard block
 block discarded – undo
208 208
      */
209 209
     protected function registerClasses()
210 210
     {
211
-        $this->app->bind('quota.storage.file', function ($app, $params) {
211
+        $this->app->bind('quota.storage.file', function($app, $params) {
212 212
             return new FileStorage($params['path']);
213 213
         });
214 214
 
215
-        $this->app->bind('quota.rate', function ($app, $params) {
215
+        $this->app->bind('quota.rate', function($app, $params) {
216 216
             return new Rate($params['limit'], $params['period']);
217 217
         });
218 218
 
219
-        $this->app->bind('quota.bucket', function ($app, $params) {
219
+        $this->app->bind('quota.bucket', function($app, $params) {
220 220
             return new TokenBucket($params['capacity'], $params['rate'], $params['storage']);
221 221
         });
222 222
 
223
-        $this->app->bind('quota.blocker', function ($app, $params) {
223
+        $this->app->bind('quota.blocker', function($app, $params) {
224 224
             return new BlockingConsumer($params['bucket']);
225 225
         });
226 226
 
Please login to merge, or discard this patch.
src/Console/Commands/ResetQuotaLog.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -80,23 +80,23 @@
 block discarded – undo
80 80
                 $changes = DB::select('SELECT changes()');
81 81
                 if (! $this->sqliteUpdateDidChange($changes)) {
82 82
                     $sql = 'INSERT INTO quotalog' .
83
-                      ' (' .
84
-                      ' `date`' .
85
-                      ', `connection`' .
86
-                      ', `hits`' .
87
-                      ', `misses`' .
88
-                      ', `created_at`' .
89
-                      ', `updated_at`' .
90
-                      ')' .
91
-                      ' VALUES' .
92
-                      ' (' .
93
-                      ' :date' .
94
-                      ', :connection' .
95
-                      ', :hits' .
96
-                      ', :misses' .
97
-                      ', :created_at' .
98
-                      ', :updated_at' .
99
-                      ')';
83
+                        ' (' .
84
+                        ' `date`' .
85
+                        ', `connection`' .
86
+                        ', `hits`' .
87
+                        ', `misses`' .
88
+                        ', `created_at`' .
89
+                        ', `updated_at`' .
90
+                        ')' .
91
+                        ' VALUES' .
92
+                        ' (' .
93
+                        ' :date' .
94
+                        ', :connection' .
95
+                        ', :hits' .
96
+                        ', :misses' .
97
+                        ', :created_at' .
98
+                        ', :updated_at' .
99
+                        ')';
100 100
 
101 101
                     $this->doUpsertStatement($sql);
102 102
                 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
     {
51 51
         switch (DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
52 52
             case 'mysql':
53
-                $sql = 'INSERT INTO quotalog' .
54
-                ' (date, connection, hits, misses, created_at, updated_at)' .
55
-                ' VALUES' .
56
-                ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)' .
57
-                ' ON DUPLICATE KEY UPDATE' .
58
-                ' hits = VALUES(hits),' .
59
-                ' misses = VALUES(misses),' .
53
+                $sql = 'INSERT INTO quotalog'.
54
+                ' (date, connection, hits, misses, created_at, updated_at)'.
55
+                ' VALUES'.
56
+                ' ( :date, :connection, :hits, :misses, :created_at, :updated_at)'.
57
+                ' ON DUPLICATE KEY UPDATE'.
58
+                ' hits = VALUES(hits),'.
59
+                ' misses = VALUES(misses),'.
60 60
                 ' updated_at = VALUES(updated_at)';
61 61
 
62 62
                 $this->doUpsertStatement($sql);
@@ -66,36 +66,36 @@  discard block
 block discarded – undo
66 66
                 $date = $this->argument('date');
67 67
                 $connection = $this->argument('connection');
68 68
 
69
-                $sql = 'UPDATE quotalog' .
70
-                ' SET `date` = :date' .
71
-                ', `connection` = :connection' .
72
-                ', `hits` = :hits' .
73
-                ', `misses` = :misses' .
74
-                ', `updated_at` = :updated_at' .
75
-                ' WHERE `date` = ' . '\''. $date . '\'' .
76
-                ' AND `connection` = ' . '\'' . $connection . '\'';
69
+                $sql = 'UPDATE quotalog'.
70
+                ' SET `date` = :date'.
71
+                ', `connection` = :connection'.
72
+                ', `hits` = :hits'.
73
+                ', `misses` = :misses'.
74
+                ', `updated_at` = :updated_at'.
75
+                ' WHERE `date` = '.'\''.$date.'\''.
76
+                ' AND `connection` = '.'\''.$connection.'\'';
77 77
 
78 78
                 $this->doUpdateStatement($sql);
79 79
 
80 80
                 $changes = DB::select('SELECT changes()');
81
-                if (! $this->sqliteUpdateDidChange($changes)) {
82
-                    $sql = 'INSERT INTO quotalog' .
83
-                      ' (' .
84
-                      ' `date`' .
85
-                      ', `connection`' .
86
-                      ', `hits`' .
87
-                      ', `misses`' .
88
-                      ', `created_at`' .
89
-                      ', `updated_at`' .
90
-                      ')' .
91
-                      ' VALUES' .
92
-                      ' (' .
93
-                      ' :date' .
94
-                      ', :connection' .
95
-                      ', :hits' .
96
-                      ', :misses' .
97
-                      ', :created_at' .
98
-                      ', :updated_at' .
81
+                if (!$this->sqliteUpdateDidChange($changes)) {
82
+                    $sql = 'INSERT INTO quotalog'.
83
+                      ' ('.
84
+                      ' `date`'.
85
+                      ', `connection`'.
86
+                      ', `hits`'.
87
+                      ', `misses`'.
88
+                      ', `created_at`'.
89
+                      ', `updated_at`'.
90
+                      ')'.
91
+                      ' VALUES'.
92
+                      ' ('.
93
+                      ' :date'.
94
+                      ', :connection'.
95
+                      ', :hits'.
96
+                      ', :misses'.
97
+                      ', :created_at'.
98
+                      ', :updated_at'.
99 99
                       ')';
100 100
 
101 101
                     $this->doUpsertStatement($sql);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             default:
106 106
                 throw new \ErrorException(
107 107
                     __CLASS__.'::'.__FUNCTION__.
108
-                    ' Driver: ' . $driver . ' not supported.'
108
+                    ' Driver: '.$driver.' not supported.'
109 109
                 );
110 110
         }
111 111
     }
Please login to merge, or discard this patch.
src/Helpers/MigrateTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
             //run specific files
51 51
 
52 52
             foreach ($files as $file) {
53
-                $file = $this->migrations_path . "/" . $file;
53
+                $file = $this->migrations_path."/".$file;
54 54
 
55 55
                 $fileSystem->requireOnce($file);
56 56
                 $migrationClass = $classFinder->findClass($file);
Please login to merge, or discard this patch.