Completed
Push — master ( 73da6c...3501ae )
by Aleksandar
26:14
created
src/Core/Service/AdminUserService.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Core\Service;
5 5
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function loginUser($email, $password)
63 63
     {
64
-        if(!$email || !$password) {
64
+        if (!$email || !$password) {
65 65
             throw new \Exception('Both email and password are required.', 400);
66 66
         }
67 67
 
68 68
         $user = $this->adminUsersMapper->getByEmail($email);
69 69
 
70
-        if(!$user) {
70
+        if (!$user) {
71 71
             throw new \Exception('User does not exist.');
72 72
         }
73 73
 
74
-        if(!$this->crypt->verify($password, $user->password)) {
74
+        if (!$this->crypt->verify($password, $user->password)) {
75 75
             throw new \Exception('Password does not match.');
76 76
         }
77 77
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     {
118 118
         $filter = $this->adminUserFilter->getInputFilter()->setData($data);
119 119
 
120
-        if(!$filter->isValid()) {
120
+        if (!$filter->isValid()) {
121 121
             throw new FilterException($filter->getMessages());
122 122
         }
123 123
 
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
                 'profile_img' => $this->upload->uploadImage($data, 'profile_img')
127 127
             ];
128 128
 
129
-        unset($data['confirm_password']);
130
-        $data['password']        = $this->crypt->create($data['password']);
131
-        $data['admin_user_id']   = Uuid::uuid1()->toString();
132
-        $data['admin_user_uuid'] = (new MysqlUuid($data['admin_user_id']))->toFormat(new Binary);
129
+        unset($data[ 'confirm_password' ]);
130
+        $data[ 'password' ]        = $this->crypt->create($data[ 'password' ]);
131
+        $data[ 'admin_user_id' ]   = Uuid::uuid1()->toString();
132
+        $data[ 'admin_user_uuid' ] = (new MysqlUuid($data[ 'admin_user_id' ]))->toFormat(new Binary);
133 133
 
134 134
         return $this->adminUsersMapper->insert($data);
135 135
     }
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
         $filter = $this->adminUserFilter->getInputFilter()->setData($data);
144 144
 
145 145
         // we dont want to force user to enter the password again
146
-        if($data['password'] == '') {
146
+        if ($data[ 'password' ] == '') {
147 147
             $filter->remove('password');
148 148
             $filter->remove('confirm_password');
149 149
         }
150 150
 
151 151
         // if we want to keep same email
152
-        if($user->email == $data['email']) {
152
+        if ($user->email == $data[ 'email' ]) {
153 153
             $filter->remove('email');
154 154
         }
155 155
 
156
-        if(!$filter->isValid()) {
156
+        if (!$filter->isValid()) {
157 157
             throw new FilterException($filter->getMessages());
158 158
         }
159 159
 
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
             ];
164 164
 
165 165
         // We dont want to force user to re-upload image on edit
166
-        if(!$data['face_img']) {
167
-            unset($data['face_img']);
166
+        if (!$data[ 'face_img' ]) {
167
+            unset($data[ 'face_img' ]);
168 168
         }
169 169
 
170
-        if(!$data['profile_img']) {
171
-            unset($data['profile_img']);
170
+        if (!$data[ 'profile_img' ]) {
171
+            unset($data[ 'profile_img' ]);
172 172
         }
173 173
 
174
-        if(isset($data['password'])) {
175
-            unset($data['confirm_password']);
176
-            $data['password'] = $this->crypt->create($data['password']);
174
+        if (isset($data[ 'password' ])) {
175
+            unset($data[ 'confirm_password' ]);
176
+            $data[ 'password' ] = $this->crypt->create($data[ 'password' ]);
177 177
         }
178 178
 
179
-        return $this->adminUsersMapper->update($data, ['admin_user_id' => $userId]);
179
+        return $this->adminUsersMapper->update($data, [ 'admin_user_id' => $userId ]);
180 180
     }
181 181
 
182 182
     /**
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function delete($userId)
189 189
     {
190
-        return (bool)$this->adminUsersMapper->delete(['admin_user_id' => $userId]);
190
+        return (bool) $this->adminUsersMapper->delete([ 'admin_user_id' => $userId ]);
191 191
     }
192 192
 
193 193
     /**
Please login to merge, or discard this patch.
src/Core/Mapper/AdminUsersMapper.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Core\Mapper;
5 5
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
     public function get($id)
35 35
     {
36
-        return $this->select(['admin_user_id' => $id])->current();
36
+        return $this->select([ 'admin_user_id' => $id ])->current();
37 37
     }
38 38
 
39 39
     /**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function getByEmail(string $email)
46 46
     {
47
-        return $this->select(['email' => $email])->current();
47
+        return $this->select([ 'email' => $email ])->current();
48 48
     }
49 49
 
50 50
     /**
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function updateLogin(string $userId): int
57 57
     {
58
-        return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_id' => $userId]);
58
+        return $this->update([ 'last_login' => date('Y-m-d H:i:s') ], [ 'admin_user_id' => $userId ]);
59 59
     }
60 60
 
61 61
     public function getPaginationSelect($userId)
62 62
     {
63
-        $select = $this->getSql()->select()->order(['created_at' => 'desc']);
63
+        $select = $this->getSql()->select()->order([ 'created_at' => 'desc' ]);
64 64
 
65 65
         $select->where->notEqualTo('admin_user_id', $userId);
66 66
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     public function getRandom($limit)
71 71
     {
72 72
         $select = $this->getSql()->select()
73
-            ->where(['status' => 1])
73
+            ->where([ 'status' => 1 ])
74 74
             ->order(new Expression('rand()'))
75 75
             ->limit($limit);
76 76
 
Please login to merge, or discard this patch.
src/Core/Factory/Service/AdminUserServiceFactory.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Core\Factory\Service;
5 5
 
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
      */
21 21
     public function __invoke(ContainerInterface $container): AdminUserService
22 22
     {
23
-        $config = $container->get('config')['upload'];
24
-        $upload = new Upload($config['public_path'], $config['non_public_path']);
23
+        $config = $container->get('config')[ 'upload' ];
24
+        $upload = new Upload($config[ 'public_path' ], $config[ 'non_public_path' ]);
25 25
 
26 26
         return new AdminUserService(
27 27
             new Bcrypt(),
Please login to merge, or discard this patch.
data/phinx/migrations/20160908142829_admin_users.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,25 +8,25 @@
 block discarded – undo
8 8
 {
9 9
     public function up()
10 10
     {
11
-        $this->table('admin_users', ['id' => false, 'primary_key' => 'admin_user_uuid'])
12
-            ->addColumn('admin_user_uuid', 'binary', ['limit' => 16])
11
+        $this->table('admin_users', [ 'id' => false, 'primary_key' => 'admin_user_uuid' ])
12
+            ->addColumn('admin_user_uuid', 'binary', [ 'limit' => 16 ])
13 13
             ->addColumn('admin_user_id', 'text')
14 14
             ->addColumn('first_name', 'text')
15 15
             ->addColumn('last_name', 'text')
16
-            ->addColumn('introduction', 'text', ['null' => true])
17
-            ->addColumn('email', 'string', ['limit' => 128])
18
-            ->addColumn('password', 'char', ['limit' => 60])
19
-            ->addColumn('status', 'integer', ['default' => 0])// 0 => not active, 1 = active
20
-            ->addColumn('face_img', 'text', ['null' => true])
21
-            ->addColumn('profile_img', 'text', ['null' => true])
22
-            ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
23
-            ->addColumn('last_login', 'datetime', ['null' => true])
24
-            ->addIndex(['email'], ['name' => 'email_INDEX'])
16
+            ->addColumn('introduction', 'text', [ 'null' => true ])
17
+            ->addColumn('email', 'string', [ 'limit' => 128 ])
18
+            ->addColumn('password', 'char', [ 'limit' => 60 ])
19
+            ->addColumn('status', 'integer', [ 'default' => 0 ])// 0 => not active, 1 = active
20
+            ->addColumn('face_img', 'text', [ 'null' => true ])
21
+            ->addColumn('profile_img', 'text', [ 'null' => true ])
22
+            ->addColumn('created_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ])
23
+            ->addColumn('last_login', 'datetime', [ 'null' => true ])
24
+            ->addIndex([ 'email' ], [ 'name' => 'email_INDEX' ])
25 25
             ->create();
26 26
 
27 27
         $faker = Faker\Factory::create();
28 28
         $count = rand(100, 150);
29
-        for($i = 0; $i < $count; $i++) {
29
+        for ($i = 0; $i < $count; $i++) {
30 30
             $id        = $faker->uuid;
31 31
             $mysqluuid = (new Uuid($id))->toFormat(new Binary());
32 32
             $data      = [
Please login to merge, or discard this patch.
data/phinx/migrations/20161003183350_category.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@
 block discarded – undo
9 9
 
10 10
     public function up()
11 11
     {
12
-        $this->table('category', ['id' => false, 'primary_key' => 'category_uuid'])
13
-            ->addColumn('category_uuid', 'binary', ['limit' => 16])
12
+        $this->table('category', [ 'id' => false, 'primary_key' => 'category_uuid' ])
13
+            ->addColumn('category_uuid', 'binary', [ 'limit' => 16 ])
14 14
             ->addColumn('category_id', 'text')
15 15
             ->addColumn('name', 'text')
16 16
             ->addColumn('slug', 'text')
Please login to merge, or discard this patch.
src/Article/src/Filter/VideoFilter.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -12,56 +12,56 @@
 block discarded – undo
12 12
 
13 13
     public function getInputFilter()
14 14
     {
15
-        if(!$this->inputFilter) {
15
+        if (!$this->inputFilter) {
16 16
             $inputFilter = new InputFilter();
17 17
 
18 18
             $inputFilter->add([
19 19
                 'name'       => 'title',
20 20
                 'required'   => true,
21
-                'filters'    => [['name' => 'StringTrim']],
21
+                'filters'    => [ [ 'name' => 'StringTrim' ] ],
22 22
                 'validators' => [
23
-                    ['name' => 'NotEmpty'],
24
-                    ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]],
23
+                    [ 'name' => 'NotEmpty' ],
24
+                    [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 100 ] ],
25 25
                 ],
26 26
             ]);
27 27
 
28 28
             $inputFilter->add([
29 29
                 'name'       => 'sub_title',
30 30
                 'required'   => false,
31
-                'filters'    => [['name' => 'StringTrim']],
31
+                'filters'    => [ [ 'name' => 'StringTrim' ] ],
32 32
                 'validators' => [
33
-                    ['name' => 'NotEmpty'],
34
-                    ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 500]],
33
+                    [ 'name' => 'NotEmpty' ],
34
+                    [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 500 ] ],
35 35
                 ],
36 36
             ]);
37 37
 
38 38
             $inputFilter->add([
39 39
                 'name'       => 'body',
40 40
                 'required'   => true,
41
-                'filters'    => [['name' => 'StringTrim']],
41
+                'filters'    => [ [ 'name' => 'StringTrim' ] ],
42 42
                 'validators' => [
43
-                    ['name' => 'NotEmpty'],
44
-                    ['name' => 'StringLength', 'options' => ['min' => 2]],
43
+                    [ 'name' => 'NotEmpty' ],
44
+                    [ 'name' => 'StringLength', 'options' => [ 'min' => 2 ] ],
45 45
                 ],
46 46
             ]);
47 47
 
48 48
             $inputFilter->add([
49 49
                 'name'       => 'lead',
50 50
                 'required'   => true,
51
-                'filters'    => [['name' => 'StringTrim']],
51
+                'filters'    => [ [ 'name' => 'StringTrim' ] ],
52 52
                 'validators' => [
53
-                    ['name' => 'NotEmpty'],
54
-                    ['name' => 'StringLength', 'options' => ['min' => 2]],
53
+                    [ 'name' => 'NotEmpty' ],
54
+                    [ 'name' => 'StringLength', 'options' => [ 'min' => 2 ] ],
55 55
                 ],
56 56
             ]);
57 57
 
58 58
             $inputFilter->add([
59 59
                 'name'       => 'video_url',
60 60
                 'required'   => true,
61
-                'filters'    => [['name' => 'StringTrim']],
61
+                'filters'    => [ [ 'name' => 'StringTrim' ] ],
62 62
                 'validators' => [
63
-                    ['name' => 'NotEmpty'],
64
-                    ['name' => 'StringLength'],
63
+                    [ 'name' => 'NotEmpty' ],
64
+                    [ 'name' => 'StringLength' ],
65 65
                 ],
66 66
             ]);
67 67
 
Please login to merge, or discard this patch.
src/Article/src/Mapper/ArticleVideosMapper.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Article\Mapper;
5 5
 
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
34 34
     public function getPaginationSelect($isActive = null)
35 35
     {
36 36
         $select = $this->getSql()->select()
37
-            ->join('articles', 'article_videos.article_uuid = articles.article_uuid', ['slug', 'published_at', 'status', 'article_id'])
38
-            ->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', ['admin_user_id', 'first_name', 'last_name'])
39
-            ->where(['articles.type' => ArticleType::POST])
40
-            ->order(['articles.created_at' => 'desc']);
37
+            ->join('articles', 'article_videos.article_uuid = articles.article_uuid', [ 'slug', 'published_at', 'status', 'article_id' ])
38
+            ->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', [ 'admin_user_id', 'first_name', 'last_name' ])
39
+            ->where([ 'articles.type' => ArticleType::POST ])
40
+            ->order([ 'articles.created_at' => 'desc' ]);
41 41
 
42
-        if($isActive !== null) {
43
-            $select->where(['articles.status' => (int)$isActive]);
42
+        if ($isActive !== null) {
43
+            $select->where([ 'articles.status' => (int) $isActive ]);
44 44
         }
45 45
 
46 46
         return $select;
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
     public function get($id)
50 50
     {
51 51
         $select = $this->getSql()->select()
52
-            ->columns(['title', 'body', 'lead', 'featured_img', 'main_img', 'video_url', 'sub_title'])
52
+            ->columns([ 'title', 'body', 'lead', 'featured_img', 'main_img', 'video_url', 'sub_title' ])
53 53
             ->join('articles', 'article_videos.article_uuid = articles.article_uuid')
54
-            ->where(['articles.article_id' => $id]);
54
+            ->where([ 'articles.article_id' => $id ]);
55 55
 
56 56
         return $this->selectWith($select)->current();
57 57
     }
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
     public function getLatest($limit = 50)
60 60
     {
61 61
         $select = $this->getSql()->select()
62
-            ->join('articles', 'article_videos.article_uuid = articles.article_uuid', ['article_id', 'slug', 'published_at'])
63
-            ->where(['articles.status' => 1])
64
-            ->order(['published_at' => 'desc'])
62
+            ->join('articles', 'article_videos.article_uuid = articles.article_uuid', [ 'article_id', 'slug', 'published_at' ])
63
+            ->where([ 'articles.status' => 1 ])
64
+            ->order([ 'published_at' => 'desc' ])
65 65
             ->limit($limit);
66 66
 
67 67
         return $this->selectWith($select);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     {
72 72
         $select = $this->getSql()->select()
73 73
             ->join('articles', 'article_videos.article_uuid = articles.article_uuid')
74
-            ->where(['articles.slug' => $slug]);
74
+            ->where([ 'articles.slug' => $slug ]);
75 75
 
76 76
         return $this->selectWith($select)->current();
77 77
     }
Please login to merge, or discard this patch.
data/phinx/migrations/20161229132336_videos.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 {
11 11
     public function up()
12 12
     {
13
-        $this->table('article_videos', ['id' => false])
14
-            ->addColumn('article_uuid', 'binary', ['limit' => 16])
13
+        $this->table('article_videos', [ 'id' => false ])
14
+            ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ])
15 15
             ->addColumn('title', 'text')
16
-            ->addColumn('sub_title', 'text', ['null' => true])
16
+            ->addColumn('sub_title', 'text', [ 'null' => true ])
17 17
             ->addColumn('body', 'text')
18 18
             ->addColumn('lead', 'text')
19 19
             ->addColumn('video_url', 'text')
20
-            ->addColumn('featured_img', 'text', ['null' => true])
21
-            ->addColumn('main_img', 'text', ['null' => true])
22
-            ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION'])
20
+            ->addColumn('featured_img', 'text', [ 'null' => true ])
21
+            ->addColumn('main_img', 'text', [ 'null' => true ])
22
+            ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ])
23 23
             ->create();
24 24
 
25 25
 //        $this->insertDummyData();
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 
33 33
     private function insertDummyData()
34 34
     {
35
-        $ids  = [];
35
+        $ids  = [ ];
36 36
         $rows = $this->fetchAll('select admin_user_uuid from admin_users;');
37
-        foreach($rows as $r) {
38
-            $ids[] = $r['admin_user_uuid'];
37
+        foreach ($rows as $r) {
38
+            $ids[ ] = $r[ 'admin_user_uuid' ];
39 39
         }
40 40
 
41 41
         $faker      = Faker\Factory::create();
@@ -48,19 +48,19 @@  discard block
 block discarded – undo
48 48
         ];
49 49
 
50 50
         // Download N images and set it randomly to posts
51
-        for($i = 0; $i < 5; $i++) {
51
+        for ($i = 0; $i < 5; $i++) {
52 52
             $image       = $faker->image();
53 53
             $destination = $upload->getPath(basename($image));
54 54
             rename($image, $destination);
55
-            $mainImg[] = substr($destination, strlen('/var/www/unfinished/public'));
55
+            $mainImg[ ] = substr($destination, strlen('/var/www/unfinished/public'));
56 56
 
57 57
             $image       = $faker->image();
58 58
             $destination = $upload->getPath(basename($image));
59 59
             rename($image, $destination);
60
-            $featuredImg[] = substr($destination, strlen('/var/www/unfinished/public'));
60
+            $featuredImg[ ] = substr($destination, strlen('/var/www/unfinished/public'));
61 61
         }
62 62
 
63
-        for($i = 0; $i < $count; $i++) {
63
+        for ($i = 0; $i < $count; $i++) {
64 64
             $id        = $faker->uuid;
65 65
             $mysqluuid = (new Uuid($id))->toFormat(new Binary());
66 66
             $title     = $faker->sentence(7, 20);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
                 'article_id'      => $id,
71 71
                 'slug'            => strtolower(trim(preg_replace('~[^\pL\d]+~u', '-', $title), '-')),
72 72
                 'status'          => 1,
73
-                'admin_user_uuid' => $ids[array_rand($ids)],
73
+                'admin_user_uuid' => $ids[ array_rand($ids) ],
74 74
                 'type'            => ArticleType::POST
75 75
             ];
76 76
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
                 'title'        => $title,
80 80
                 'body'         => $faker->paragraph(15),
81 81
                 'lead'         => $faker->paragraph(5),
82
-                'main_img'     => $mainImg[array_rand($mainImg)],
83
-                'featured_img' => $featuredImg[array_rand($featuredImg)],
84
-                'video_url'    => $embedCodes[rand(0, 2)]
82
+                'main_img'     => $mainImg[ array_rand($mainImg) ],
83
+                'featured_img' => $featuredImg[ array_rand($featuredImg) ],
84
+                'video_url'    => $embedCodes[ rand(0, 2) ]
85 85
             ];
86 86
 
87 87
             $this->insert('articles', $article);
Please login to merge, or discard this patch.