Completed
Push — master ( c7c564...8bfd95 )
by Dan Michael O.
11:45
created
app/CachedImage.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -13,6 +13,9 @@  discard block
 block discarded – undo
13 13
     public $maxHeight;
14 14
     protected $_metadata;
15 15
 
16
+    /**
17
+     * @param string $url
18
+     */
16 19
     public function __construct($url, $maxHeight = 0, AdapterInterface $filesystem = null, ImageManager $imageManager = null)
17 20
     {
18 21
         $this->sourceUrl = $url;
@@ -37,6 +40,9 @@  discard block
 block discarded – undo
37 40
         return $this->_metadata;
38 41
     }
39 42
 
43
+    /**
44
+     * @param string $file
45
+     */
40 46
     protected function setMetadata($file, Image $img)
41 47
     {
42 48
         $this->_metadata = [
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
         $this->imageManager = $imageManager ?: app('Intervention\Image\ImageManager');
22 22
         $maxAge = 3153600; // 30 days
23 23
         $this->fsConfig = new FlysystemConfig([
24
-            'CacheControl' => 'max-age=' . $maxAge . ', public',
24
+            'CacheControl' => 'max-age='.$maxAge.', public',
25 25
         ]);
26 26
     }
27 27
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
     public function basename()
71 71
     {
72
-        return sha1($this->sourceUrl . $this->maxHeight);
72
+        return sha1($this->sourceUrl.$this->maxHeight);
73 73
     }
74 74
 
75 75
     /**
@@ -95,24 +95,24 @@  discard block
 block discarded – undo
95 95
     {
96 96
         $data = $this->download();
97 97
         if (!$data) {
98
-            throw new \ErrorException('[CoverCache] Failed to download ' . $this->sourceUrl);
98
+            throw new \ErrorException('[CoverCache] Failed to download '.$this->sourceUrl);
99 99
         }
100 100
 
101 101
         $img = $this->imageManager->make($data);
102 102
         if ($this->maxHeight && $img->height() > $this->maxHeight) {
103
-            \Log::debug('Resizing from ' . $img->height() . ' to ' . $this->maxHeight);
103
+            \Log::debug('Resizing from '.$img->height().' to '.$this->maxHeight);
104 104
             $img->heighten($this->maxHeight);
105 105
             $data = strval($img->encode('jpg'));
106 106
         }
107 107
 
108 108
         $this->setMetadata($data, $img);
109 109
 
110
-        \Log::debug('Storing image as ' . $img->width() . ' x ' . $img->height() . ', ' . strlen($data) . ' bytes');
110
+        \Log::debug('Storing image as '.$img->width().' x '.$img->height().', '.strlen($data).' bytes');
111 111
         if (!$this->filesystem->write($this->basename(), $data, $this->fsConfig)) {
112
-            throw new \ErrorException('[CoverCache] Failed to upload to S3: ' . $this->sourceUrl);
112
+            throw new \ErrorException('[CoverCache] Failed to upload to S3: '.$this->sourceUrl);
113 113
         }
114 114
 
115
-        \Log::debug('Wrote cached version of ' . $this->sourceUrl . ' as ' . $this->basename());
115
+        \Log::debug('Wrote cached version of '.$this->sourceUrl.' as '.$this->basename());
116 116
 
117 117
         return $this;
118 118
     }
Please login to merge, or discard this patch.
app/Cover.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
     /**
38 38
      * The document the cover belongs to.
39 39
      *
40
-     * @return Document
40
+     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
41 41
      */
42 42
     public function document()
43 43
     {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     public function invalidateCache()
79 79
     {
80 80
         if (!is_null($this->width) && !is_null($this->height)) {
81
-            \Log::debug('Invalidating cache. Old version was ' . $this->width . ' x ' . $this->height);
81
+            \Log::debug('Invalidating cache. Old version was '.$this->width.' x '.$this->height);
82 82
         }
83 83
         $this->width = null;
84 84
         $this->height = null;
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
             throw new \ErrorException('[Cover] Cannot cache when no URL set.');
124 124
         }
125 125
         if ($this->isCached()) {
126
-            \Log::debug('Already cached: ' . $this->url);
126
+            \Log::debug('Already cached: '.$this->url);
127 127
 
128 128
             return;
129 129
         }
130 130
 
131
-        \Log::debug('Cache add: ' . $this->url);
131
+        \Log::debug('Cache add: '.$this->url);
132 132
 
133 133
         $orig = \CoverCache::put($this->url);
134 134
 
Please login to merge, or discard this patch.
app/DescriptionScraper.php 2 patches
Doc Comments   +8 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@  discard block
 block discarded – undo
15 15
     /**
16 16
      * Create a new scraper.
17 17
      *
18
-     * @param Client $client
19 18
      */
20 19
     public function __construct()
21 20
     {
@@ -35,6 +34,11 @@  discard block
 block discarded – undo
35 34
         }
36 35
     }
37 36
 
37
+    /**
38
+     * @param string $msg
39
+     * @param Document $doc
40
+     * @param string[] $args
41
+     */
38 42
     public function notify($msg, $doc, $args, $level = 'warning')
39 43
     {
40 44
         $msg = vsprintf($msg, $args);
@@ -46,6 +50,9 @@  discard block
 block discarded – undo
46 50
         ])->send();
47 51
     }
48 52
 
53
+    /**
54
+     * @param string $url
55
+     */
49 56
     public function scrape($url)
50 57
     {
51 58
         foreach ($this->scrapers as $scraper) {
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
         $msg = vsprintf($msg, $args);
41 41
         $docLink = sprintf('<http://colligator.biblionaut.net/api/documents/%s|#%s> ', $doc->id, $doc->id);
42 42
         \Slack::attach([
43
-            'fallback' => '#' . $doc->id . ' ' . $msg,
44
-            'text'     => $docLink . $msg,
43
+            'fallback' => '#'.$doc->id.' '.$msg,
44
+            'text'     => $docLink.$msg,
45 45
             'color'    => $level,
46 46
         ])->send();
47 47
     }
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function updateDocument(Document $doc, $url)
67 67
     {
68
-        \Log::debug('[DescriptionScraper] Looking for decription for ' . $doc->id . ' at ' . $url);
68
+        \Log::debug('[DescriptionScraper] Looking for decription for '.$doc->id.' at '.$url);
69 69
 
70 70
         if (preg_match('/(damm.no)/', $url)) {
71
-            \Log::debug('[DescriptionScraper] Ignoring URL: ' . $url);
71
+            \Log::debug('[DescriptionScraper] Ignoring URL: '.$url);
72 72
 
73 73
             return;
74 74
         }
@@ -76,18 +76,18 @@  discard block
 block discarded – undo
76 76
         try {
77 77
             $result = $this->scrape($url);
78 78
         } catch (TransferException $e) {
79
-            \Log::error('[DescriptionScraper] Transfer failed: ' . $e->getMessage());
79
+            \Log::error('[DescriptionScraper] Transfer failed: '.$e->getMessage());
80 80
             $this->notify('*DescriptionScraper* failed to fetch: %s', $doc, [$url]);
81 81
 
82 82
             return;
83 83
         } catch (Scrapers\ScrapeException $e) {
84
-            \Log::error('[DescriptionScraper] Scraping failed: ' . $e->getMessage());
84
+            \Log::error('[DescriptionScraper] Scraping failed: '.$e->getMessage());
85 85
             $this->notify('*DescriptionScraper* / %s failed to find a text at: %s', $doc, [$e->getMessage(), $url]);
86 86
 
87 87
             return;
88 88
         }
89 89
         if (is_null($result)) {
90
-            \Log::error('Encountered URL not recognized by any scraper: ' . $url);
90
+            \Log::error('Encountered URL not recognized by any scraper: '.$url);
91 91
             $this->notify('*DescriptionScraper* encountered URL not recognized by any sraper: %s', $doc, [$url]);
92 92
 
93 93
             return;
Please login to merge, or discard this patch.
app/Http/Controllers/DocumentsController.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * Display a listing of the resource.
15 15
      *
16
-     * @return Response
16
+     * @return \Illuminate\Http\JsonResponse
17 17
      */
18 18
     public function index(SearchDocumentsRequest $request, DocumentsIndex $se)
19 19
     {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      * @param DocumentsIndex $se
66 66
      * @param int            $id
67 67
      *
68
-     * @return Response
68
+     * @return \Illuminate\Http\JsonResponse
69 69
      */
70 70
     public function show(Request $request, DocumentsIndex $se, $id)
71 71
     {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     /**
126 126
      * Show cover.
127 127
      *
128
-     * @return Response
128
+     * @return \Illuminate\Http\JsonResponse
129 129
      */
130 130
     public function cover($document_id)
131 131
     {
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     /**
140 140
      * Store cover.
141 141
      *
142
-     * @return Response
142
+     * @return \Illuminate\Http\JsonResponse
143 143
      */
144 144
     public function storeCover($document_id, Request $request, DocumentsIndex $se)
145 145
     {
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     /**
172 172
      * Store description.
173 173
      *
174
-     * @return Response
174
+     * @return \Illuminate\Http\JsonResponse
175 175
      */
176 176
     public function storeDescription($document_id, Request $request, DocumentsIndex $se)
177 177
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace Colligator\Http\Controllers;
4 4
 
5
-use Colligator\Cover;
6 5
 use Colligator\Document;
7 6
 use Colligator\Http\Requests\SearchDocumentsRequest;
8 7
 use Colligator\Search\DocumentsIndex;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         try {
153 153
             $cover = $doc->storeCover($request->url);
154 154
         } catch (\ErrorException $e) {
155
-            \Log::error('Failed to cache cover ' . $request->url . '. Got error: ' . $e->getMessage());
155
+            \Log::error('Failed to cache cover '.$request->url.'. Got error: '.$e->getMessage());
156 156
 
157 157
             return response()->json([
158 158
                 'result' => 'error',
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         ];
190 190
         $doc->save();
191 191
 
192
-        \Log::info('Stored new description for ' . $document_id);
192
+        \Log::info('Stored new description for '.$document_id);
193 193
 
194 194
         $se->indexById($document_id);
195 195
 
Please login to merge, or discard this patch.
app/Http/Controllers/OntosaurController.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * Display a listing of the resource.
11 11
      *
12
-     * @return Response
12
+     * @return \Illuminate\Http\JsonResponse
13 13
      */
14 14
     public function index()
15 15
     {
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @param int $id
23 23
      *
24
-     * @return Response
24
+     * @return \Illuminate\Http\JsonResponse
25 25
      */
26 26
     public function show($id)
27 27
     {
Please login to merge, or discard this patch.
app/Search/DocumentsIndex.php 2 patches
Doc Comments   +17 added lines, -1 removed lines patch added patch discarded remove patch
@@ -168,6 +168,7 @@  discard block
 block discarded – undo
168 168
      * Returns the number of documents the subject is used on.
169 169
      *
170 170
      * @param int $id
171
+     * @param string $type
171 172
      *
172 173
      * @return int
173 174
      */
@@ -185,8 +186,8 @@  discard block
 block discarded – undo
185 186
     /**
186 187
      * Build an array of document usage count per subject.
187 188
      *
188
-     * @param array|int $subject_ids
189 189
      *
190
+     * @param integer $entity_ids
190 191
      * @return array
191 192
      */
192 193
     public function addToUsageCache($entity_ids, $type)
@@ -264,6 +265,9 @@  discard block
 block discarded – undo
264 265
         $this->index(Document::with('subjects', 'cover')->findOrFail($docId));
265 266
     }
266 267
 
268
+    /**
269
+     * @param integer $version
270
+     */
267 271
     public function createVersion($version = null)
268 272
     {
269 273
         if (is_null($version)) {
@@ -307,6 +311,9 @@  discard block
 block discarded – undo
307 311
         return $version;
308 312
     }
309 313
 
314
+    /**
315
+     * @param integer $version
316
+     */
310 317
     public function dropVersion($version)
311 318
     {
312 319
         try {
@@ -318,6 +325,9 @@  discard block
 block discarded – undo
318 325
         }
319 326
     }
320 327
 
328
+    /**
329
+     * @param string $action
330
+     */
321 331
     public function addAction(&$actions, $action, $version)
322 332
     {
323 333
         if ($version) {
@@ -325,6 +335,9 @@  discard block
 block discarded – undo
325 335
         }
326 336
     }
327 337
 
338
+    /**
339
+     * @param integer $newVersion
340
+     */
328 341
     public function activateVersion($newVersion)
329 342
     {
330 343
         $oldVersion = $this->getCurrentVersion();
@@ -336,6 +349,9 @@  discard block
 block discarded – undo
336 349
         }
337 350
     }
338 351
 
352
+    /**
353
+     * @param integer $version
354
+     */
339 355
     public function versionExists($version)
340 356
     {
341 357
         return $this->client->indices()->exists(['index' => $this->esIndex . '_v' . $version]);
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     public function sanitizeForQuery($value)
95 95
     {
96 96
         $chars = preg_quote('\\+-&|!(){}[]^~*?:');
97
-        $value = preg_replace('/([' . $chars . '])/', '\\\\\1', $value);
97
+        $value = preg_replace('/(['.$chars.'])/', '\\\\\1', $value);
98 98
 
99 99
         return $value;
100 100
         //
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
         }
127 127
         if ($request->has('collection')) {
128 128
             $col = Collection::findOrFail($request->collection);
129
-            $query[] = 'collections:"' . $this->sanitizeForQuery($col->name) . '"';
129
+            $query[] = 'collections:"'.$this->sanitizeForQuery($col->name).'"';
130 130
         }
131 131
         if ($request->has('subject')) {
132
-            $query[] = '(subjects.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' .
133
-                    ' OR subjects.NOTrBIB.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' .
134
-                    ' OR genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '")';
132
+            $query[] = '(subjects.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'.
133
+                    ' OR subjects.NOTrBIB.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'.
134
+                    ' OR genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'")';
135 135
                 // TODO: Vi bør vel antakelig skille mellom X som emne og X som form/sjanger ?
136 136
                 //       Men da må frontend si fra hva den ønsker, noe den ikke gjør enda.
137 137
         }
138 138
         if ($request->has('genre')) {
139
-            $query[] = 'genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->genre) . '"';
139
+            $query[] = 'genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->genre).'"';
140 140
         }
141 141
         if ($request->has('real')) {
142 142
             dd('`real` is (very) deprecated, please use `subject` instead.');
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     public function getUsageCount($id, $type)
175 175
     {
176 176
         $this->getFullType($type);
177
-        $arg = $type . '.' . $id;
177
+        $arg = $type.'.'.$id;
178 178
         if (is_null(array_get($this->usage, $arg))) {
179 179
             $this->addToUsageCache($id, $type);
180 180
         }
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
             ->get();
204 204
 
205 205
         foreach ($entity_ids as $sid) {
206
-            array_set($this->usage, $type . '.' . $sid, 0);
206
+            array_set($this->usage, $type.'.'.$sid, 0);
207 207
         }
208 208
 
209 209
         foreach ($res as $row) {
210
-            array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count));
210
+            array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count));
211 211
         }
212 212
     }
213 213
 
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
         $query = \DB::table('entities')
218 218
                     ->select(['entity_id', 'entity_type', \DB::raw('count(document_id) as doc_count')])
219 219
                     ->groupBy('entity_id', 'entity_type');
220
-        $query->chunk(5000, function ($rows) use ($typemap) {
220
+        $query->chunk(5000, function($rows) use ($typemap) {
221 221
             foreach ($rows as $row) {
222 222
                 $type = $typemap[$row->entity_type];
223
-                array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count));
223
+                array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count));
224 224
             }
225 225
         });
226 226
     }
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     {
238 238
         $payload = $this->basePayload();
239 239
         if (!is_null($indexVersion)) {
240
-            $payload['index'] = $this->esIndex . '_v' . $indexVersion;
240
+            $payload['index'] = $this->esIndex.'_v'.$indexVersion;
241 241
         }
242 242
         $payload['id'] = $doc->id;
243 243
 
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
         try {
248 248
             $this->client->index($payload);
249 249
         } catch (BadRequest400Exception $e) {
250
-            \Log::error('ElasticSearch returned error: ' . $e->getMessage() . '. Our request: ' . var_export($payload, true));
251
-            throw new \ErrorException('ElasticSearch failed to index the document ' . $doc->id . '. Please see the log for payload and full error response. Error message: ' . $e->getMessage());
250
+            \Log::error('ElasticSearch returned error: '.$e->getMessage().'. Our request: '.var_export($payload, true));
251
+            throw new \ErrorException('ElasticSearch failed to index the document '.$doc->id.'. Please see the log for payload and full error response. Error message: '.$e->getMessage());
252 252
         }
253 253
     }
254 254
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
         if (is_null($version)) {
270 270
             $version = $this->getCurrentVersion() + 1;
271 271
         }
272
-        $indexParams = ['index' => $this->esIndex . '_v' . $version];
272
+        $indexParams = ['index' => $this->esIndex.'_v'.$version];
273 273
         $indexParams['body']['settings']['analysis']['char_filter']['isbn_filter'] = [
274 274
             'type'        => 'pattern_replace',
275 275
             'pattern'     => '-',
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         try {
313 313
             $this->client->indices()->delete([
314
-                'index' => $this->esIndex . '_v' . $version,
314
+                'index' => $this->esIndex.'_v'.$version,
315 315
             ]);
316 316
         } catch (Missing404Exception $e) {
317 317
             # Didn't exist in the beginning, that's ok.
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public function addAction(&$actions, $action, $version)
322 322
     {
323 323
         if ($version) {
324
-            $actions[] = [$action => ['index' => $this->esIndex . '_v' . $version, 'alias' => $this->esIndex]];
324
+            $actions[] = [$action => ['index' => $this->esIndex.'_v'.$version, 'alias' => $this->esIndex]];
325 325
         }
326 326
     }
327 327
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
     public function versionExists($version)
340 340
     {
341
-        return $this->client->indices()->exists(['index' => $this->esIndex . '_v' . $version]);
341
+        return $this->client->indices()->exists(['index' => $this->esIndex.'_v'.$version]);
342 342
     }
343 343
 
344 344
     public function getCurrentVersion()
Please login to merge, or discard this patch.
app/Console/Kernel.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@
 block discarded – undo
29 29
     protected function schedule(Schedule $schedule)
30 30
     {
31 31
         $schedule->command('colligator:harvest-oaipmh samling42 --daily')
32
-                 ->dailyAt('02:00');
32
+                    ->dailyAt('02:00');
33 33
 
34 34
         // Bring subject heading usage counts up-to-date
35 35
         $schedule->command('colligator:reindex')
36
-                 ->weekly()->sundays()->at('04:00');
36
+                    ->weekly()->sundays()->at('04:00');
37 37
 
38 38
         // Check new documents for xisbn
39 39
         $schedule->command('colligator:harvest-xisbn')
40
-                 ->weekly()->saturdays()->at('04:00');
40
+                    ->weekly()->saturdays()->at('04:00');
41 41
     }
42 42
 }
Please login to merge, or discard this patch.
app/Http/routes.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 |
12 12
 */
13 13
 
14
-Route::group(['middleware' => 'cors'], function () {
14
+Route::group(['middleware' => 'cors'], function() {
15 15
 
16
-    Route::get('api/', function () {
16
+    Route::get('api/', function() {
17 17
         return view('welcome');
18 18
     });
19 19
 
Please login to merge, or discard this patch.
app/Providers/CoverCacheServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
      */
21 21
     public function register()
22 22
     {
23
-        \App::bind('covercache', function () {
23
+        \App::bind('covercache', function() {
24 24
             return new CoverCache();
25 25
         });
26 26
     }
Please login to merge, or discard this patch.