@@ -51,8 +51,8 @@ |
||
51 | 51 | } else { |
52 | 52 | throw new \InvalidArgumentException( |
53 | 53 | __CLASS__.'::'.__FUNCTION__. |
54 | - ' Invalid constant. Got: ' . $key . |
|
55 | - ' Expected: ' . print_r($constants, 1) |
|
54 | + ' Invalid constant. Got: '.$key. |
|
55 | + ' Expected: '.print_r($constants, 1) |
|
56 | 56 | ); |
57 | 57 | } |
58 | 58 | } |
@@ -30,10 +30,10 @@ |
||
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 |
@@ -35,7 +35,7 @@ discard block |
||
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 |
||
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 | ], |
@@ -60,11 +60,11 @@ discard block |
||
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 |
||
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 |
@@ -87,14 +87,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 { |
@@ -168,19 +168,19 @@ discard block |
||
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 |
||
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 |
@@ -50,13 +50,13 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -50,7 +50,7 @@ |
||
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); |
@@ -55,24 +55,24 @@ discard block |
||
55 | 55 | parent::__construct($connection); |
56 | 56 | |
57 | 57 | $this->connection = $connection; |
58 | - $this->index = 'quota.connections.' . $connection; |
|
58 | + $this->index = 'quota.connections.'.$connection; |
|
59 | 59 | |
60 | - $this->timezone = config($this->index . '.timezone'); |
|
60 | + $this->timezone = config($this->index.'.timezone'); |
|
61 | 61 | if (is_null($this->timezone)) { |
62 | 62 | $this->timezone = config('quota.default_timezone'); |
63 | 63 | } |
64 | 64 | |
65 | - $this->log_table = config($this->index . '.log_table'); |
|
65 | + $this->log_table = config($this->index.'.log_table'); |
|
66 | 66 | |
67 | 67 | //Bootstrap log if record does not exist. |
68 | 68 | $dtz = new \DateTimeZone($this->timezone); |
69 | 69 | $now = new \DateTime(date("Y-m-d"), $dtz); |
70 | 70 | $date = $now->format("Y-m-d"); |
71 | 71 | $log_records = DB::select( |
72 | - 'SELECT * FROM' . |
|
73 | - ' ' . $this->log_table . |
|
74 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
75 | - ' AND connection = ' . '\'' . $connection . '\'' |
|
72 | + 'SELECT * FROM'. |
|
73 | + ' '.$this->log_table. |
|
74 | + ' WHERE date = '.'\''.$date.'\''. |
|
75 | + ' AND connection = '.'\''.$connection.'\'' |
|
76 | 76 | ); |
77 | 77 | |
78 | 78 | if (empty($log_records)) { |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | $hits = $hits + 1; |
117 | 117 | |
118 | 118 | DB::statement( |
119 | - 'UPDATE ' . $this->log_table . |
|
120 | - ' SET hits = ' . $hits . |
|
121 | - ', updated_at = ' . '\'' . Carbon::now()->toDateTimeString() . '\'' . |
|
122 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
123 | - ' AND connection = ' . '\'' . $this->connection . '\'' |
|
119 | + 'UPDATE '.$this->log_table. |
|
120 | + ' SET hits = '.$hits. |
|
121 | + ', updated_at = '.'\''.Carbon::now()->toDateTimeString().'\''. |
|
122 | + ' WHERE date = '.'\''.$date.'\''. |
|
123 | + ' AND connection = '.'\''.$this->connection.'\'' |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | $misses = $misses + 1; |
137 | 137 | |
138 | 138 | DB::statement( |
139 | - 'UPDATE ' . $this->log_table . |
|
140 | - ' SET misses = ' . $misses . |
|
141 | - ', updated_at = ' . '\'' . Carbon::now()->toDateTimeString() . '\'' . |
|
142 | - ' WHERE date = ' . '\'' . $date . '\'' . |
|
143 | - ' AND connection = ' . '\'' . $this->connection . '\'' |
|
139 | + 'UPDATE '.$this->log_table. |
|
140 | + ' SET misses = '.$misses. |
|
141 | + ', updated_at = '.'\''.Carbon::now()->toDateTimeString().'\''. |
|
142 | + ' WHERE date = '.'\''.$date.'\''. |
|
143 | + ' AND connection = '.'\''.$this->connection.'\'' |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | if ($this->limit < ($hits + 1)) { |
163 | 163 | $this->miss($stats->misses); |
164 | 164 | throw new \ErrorException( |
165 | - __CLASS__ . '::' . __FUNCTION__ . |
|
166 | - ' Overquota. Exceeded daily limit: ' . $this->limit |
|
165 | + __CLASS__.'::'.__FUNCTION__. |
|
166 | + ' Overquota. Exceeded daily limit: '.$this->limit |
|
167 | 167 | ); |
168 | 168 | } else { |
169 | 169 | $this->hit($stats->hits); |