Completed
Pull Request — master (#20)
by Andreas
04:05
created
src/PersistenceLayer/CfpPersistenceLayer.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,6 @@
 block discarded – undo
28 28
 namespace Callingallpapers\Api\PersistenceLayer;
29 29
 
30 30
 use Callingallpapers\Api\Entity\Cfp;
31
-use Monolog\Logger;
32 31
 
33 32
 class CfpPersistenceLayer
34 33
 {
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             $cfp->setDateCfpStart(new \DateTimeImmutable());
68 68
         }
69 69
         $statement = 'INSERT into `cfp`(`dateCfpStart`, `dateCfpEnd`, `dateEventStart`, `dateEventEnd`, `name`, `uri`, `hash`, `timezone`, `description`, `eventUri`, `iconUri`, `latitude`, `longitude`, `location`, `tags`, `lastUpdate`) ' .
70
-                     'VALUES (:dateCfpStart, :dateCfpEnd, :dateEventStart, :dateEventEnd, :name, :uri, :hash, :timezone, :description, :eventUri, :iconUri, :latitude, :longitude, :location, :tags, :lastUpdate);';
70
+                        'VALUES (:dateCfpStart, :dateCfpEnd, :dateEventStart, :dateEventEnd, :name, :uri, :hash, :timezone, :description, :eventUri, :iconUri, :latitude, :longitude, :location, :tags, :lastUpdate);';
71 71
         $statement = $this->pdo->prepare($statement);
72 72
 
73 73
         $values = [
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 
130 130
         foreach ($options as $option) {
131 131
             $method = 'get' . $option;
132
-           // Merge values from tags and source before comparing!
132
+            // Merge values from tags and source before comparing!
133 133
             if (in_array($option, ['tags', 'source'])) {
134 134
                 $setter = 'set' . $option;
135 135
                 $cfp->$setter(array_merge($oldValues->$method(), $cfp->$method()));
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
         }
159 159
 
160 160
         $statement = 'UPDATE `cfp` SET '
161
-                   . implode(',', $statementElements) . ','
162
-                   . '`lastUpdate` = :lastUpdate '
163
-                   . 'WHERE `hash` = :fetchHash';
161
+                    . implode(',', $statementElements) . ','
162
+                    . '`lastUpdate` = :lastUpdate '
163
+                    . 'WHERE `hash` = :fetchHash';
164 164
         $statement = $this->pdo->prepare($statement);
165 165
         $values['fetchHash']  = $fetchHash;
166 166
         $values['lastUpdate'] = (new \DateTime('now', new \DateTimezone('UTC')))->format('c');
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
             $cfp->setLocation($item['location']);
354 354
             $cfp->setTags(explode(',', $item['tags']));
355 355
             $cfp->setLastUpdated(new \DateTimeImmutable($item['lastUpdate']));
356
-         //   $cfp->setSource(explode(',', $item['source']));
356
+            //   $cfp->setSource(explode(',', $item['source']));
357 357
 
358 358
             $list->add($cfp);
359 359
         }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         if ($cfp->getDateCfpStart()->getTimestamp() < 10000) {
67 67
             $cfp->setDateCfpStart(new \DateTimeImmutable());
68 68
         }
69
-        $statement = 'INSERT into `cfp`(`dateCfpStart`, `dateCfpEnd`, `dateEventStart`, `dateEventEnd`, `name`, `uri`, `hash`, `timezone`, `description`, `eventUri`, `iconUri`, `latitude`, `longitude`, `location`, `tags`, `lastUpdate`) ' .
69
+        $statement = 'INSERT into `cfp`(`dateCfpStart`, `dateCfpEnd`, `dateEventStart`, `dateEventEnd`, `name`, `uri`, `hash`, `timezone`, `description`, `eventUri`, `iconUri`, `latitude`, `longitude`, `location`, `tags`, `lastUpdate`) '.
70 70
                      'VALUES (:dateCfpStart, :dateCfpEnd, :dateEventStart, :dateEventEnd, :name, :uri, :hash, :timezone, :description, :eventUri, :iconUri, :latitude, :longitude, :location, :tags, :lastUpdate);';
71 71
         $statement = $this->pdo->prepare($statement);
72 72
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function update(Cfp $cfp, $fetchHash)
100 100
     {
101
-        if (! $fetchHash) {
101
+        if (!$fetchHash) {
102 102
             throw new \UnexpectedValueException('No Hash given', 400);
103 103
         }
104 104
         $oldValues = $this->select($fetchHash);
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
         ];
129 129
 
130 130
         foreach ($options as $option) {
131
-            $method = 'get' . $option;
131
+            $method = 'get'.$option;
132 132
            // Merge values from tags and source before comparing!
133 133
             if (in_array($option, ['tags', 'source'])) {
134
-                $setter = 'set' . $option;
134
+                $setter = 'set'.$option;
135 135
                 $cfp->$setter(array_merge($oldValues->$method(), $cfp->$method()));
136 136
             }
137 137
             if ($cfp->$method() !== $oldValues->$method()) {
138 138
                 if ($option == 'dateCfpStart' && $cfp->$method()->getTimestamp() < 100000) {
139 139
                     continue;
140 140
                 }
141
-                $statementElements[] = '`' . $option . '` = :' . $option;
141
+                $statementElements[] = '`'.$option.'` = :'.$option;
142 142
                 $values[$option]     = $cfp->$method();
143 143
                 if ($values[$option] instanceof \DateTimeInterface) {
144 144
                     $values[$option] = $values[$option]->format('c');
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
         }
159 159
 
160 160
         $statement = 'UPDATE `cfp` SET '
161
-                   . implode(',', $statementElements) . ','
161
+                   . implode(',', $statementElements).','
162 162
                    . '`lastUpdate` = :lastUpdate '
163 163
                    . 'WHERE `hash` = :fetchHash';
164 164
         $statement = $this->pdo->prepare($statement);
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
         $values    = [];
295 295
         $where = [];
296 296
         foreach ($parameters as $key => $value) {
297
-            if (! in_array($key, $fields)) {
297
+            if (!in_array($key, $fields)) {
298 298
                 continue;
299 299
             }
300
-            if (! is_array($value)){
300
+            if (!is_array($value)) {
301 301
                 $value = [$value];
302 302
             }
303
-            foreach($value as $itemkey => $item) {
303
+            foreach ($value as $itemkey => $item) {
304 304
                 $compare = '=';
305 305
                 if (in_array($key, [
306 306
                     'date_cfp_end',
@@ -308,19 +308,19 @@  discard block
 block discarded – undo
308 308
                     'date_event_end',
309 309
                     'date_event_start'
310 310
                 ])) {
311
-                    if (array_key_exists($key . '_compare', $parameters) && isset($parameters[$key . '_compare'][$itemkey]) && in_array($parameters[$key . '_compare'][$itemkey], ['=', '<', '>', '<>'])) {
312
-                        $compare = $parameters[$key . '_compare'][$itemkey];
311
+                    if (array_key_exists($key.'_compare', $parameters) && isset($parameters[$key.'_compare'][$itemkey]) && in_array($parameters[$key.'_compare'][$itemkey], ['=', '<', '>', '<>'])) {
312
+                        $compare = $parameters[$key.'_compare'][$itemkey];
313 313
                     }
314
-                    $where[] = 'datetime(`' . $transformer->transform($key) . '`) ' . $compare . ' datetime(:' . $key . '_' . $itemkey . ')';
314
+                    $where[] = 'datetime(`'.$transformer->transform($key).'`) '.$compare.' datetime(:'.$key.'_'.$itemkey.')';
315 315
 //                    $where[] = '`' . $transformer->transform($key) . '` ' . $compare . ' CONVERT_TZ(:' . $key . ', timezone, \'UTC\')';
316 316
                     $value = (new DateTime($item))->setTimezone(new \DateTimeZone('UTC'))->format('c');
317 317
                 } else {
318
-                    $where[] = '`' . $transformer->transform($key) . '` ' . $compare . ' :' . $key;
318
+                    $where[] = '`'.$transformer->transform($key).'` '.$compare.' :'.$key;
319 319
                 }
320
-                $values[$key . '_' . $itemkey] = $value;
320
+                $values[$key.'_'.$itemkey] = $value;
321 321
             }
322 322
         }
323
-        if (! $where) {
323
+        if (!$where) {
324 324
             throw new \UnexpectedValueException('No CFPs found', 404);
325 325
         }
326 326
 
Please login to merge, or discard this patch.
config/routes.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     \Psr\Http\Message\ResponseInterface $response
42 42
 ) use ($app){
43 43
     $params = $request->getParsedBody();
44
-    if (! is_array($params)) {
44
+    if (!is_array($params)) {
45 45
         throw new UnexpectedValueException('Expected array');
46 46
     }
47 47
 
@@ -54,18 +54,18 @@  discard block
 block discarded – undo
54 54
     $cpl->insert($cfp);
55 55
 
56 56
     $uri = $request->getUri();
57
-    $uri = $uri->withPath('v1/cfp/' . $cfp->getId());
57
+    $uri = $uri->withPath('v1/cfp/'.$cfp->getId());
58 58
     return $response->withRedirect((string)$uri, 201);
59 59
 });
60 60
 
61 61
 
62
-$app->put('/v1/cfp/{hash}', function (
62
+$app->put('/v1/cfp/{hash}', function(
63 63
     \Psr\Http\Message\ServerRequestInterface $request,
64 64
     \Psr\Http\Message\ResponseInterface $response,
65 65
     array $args
66 66
 ) use ($app){
67 67
     $params = $request->getParsedBody();
68
-    if (! is_array($params)) {
68
+    if (!is_array($params)) {
69 69
         throw new UnexpectedValueException('Expected array');
70 70
     }
71 71
 
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     $cpl->update($cfp, $args['hash']);
79 79
 
80 80
     $uri = $request->getUri();
81
-    $uri = $uri->withPath('v1/cfp/' . $cfp->getId());
81
+    $uri = $uri->withPath('v1/cfp/'.$cfp->getId());
82 82
     return $response->withHeader('Location', (string)$uri)->withStatus(204);
83 83
 });
84 84
 
85 85
 
86
-$app->delete('/v1/cfp/{id}', function (
86
+$app->delete('/v1/cfp/{id}', function(
87 87
     \Psr\Http\Message\ServerRequestInterface $request,
88 88
     \Psr\Http\Message\ResponseInterface $response
89 89
 ) use ($app){
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     return $response->withHeader('Content-Length', '0')->withStatus(204);
97 97
 });
98 98
 
99
-$app->get('/v1/search', function (
99
+$app->get('/v1/search', function(
100 100
     \Psr\Http\Message\ServerRequestInterface $request,
101 101
     \Psr\Http\Message\ResponseInterface $response,
102 102
     array $args
@@ -110,5 +110,5 @@  discard block
 block discarded – undo
110 110
 
111 111
     $cfpMapper = new \Callingallpapers\Api\Entity\CfpListMapper();
112 112
 
113
-    return $this->view->render($response, $cfpMapper->map($list), 200, 'cfp/list.twig');;
113
+    return $this->view->render($response, $cfpMapper->map($list), 200, 'cfp/list.twig'); ;
114 114
 });
Please login to merge, or discard this patch.