Completed
Pull Request — master (#42)
by Nemanja
01:57
created
src/Web/Middleware/Layout.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     public function __invoke(Request $request, Response $response, callable $next = null)
49 49
     {
50 50
         if (0 === strpos($request->getUri()->getPath(), '/admin')) {
51
-            $this->config['templates']['layout'] = 'layout/admin';
51
+            $this->config[ 'templates' ][ 'layout' ] = 'layout/admin';
52 52
         }
53 53
 
54 54
         return $next($request, $response);
Please login to merge, or discard this patch.
src/Core/Service/AdminUserService.php 4 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,6 @@
 block discarded – undo
4 4
 namespace Core\Service;
5 5
 
6 6
 use Core\Mapper\AdminUsersMapper;
7
-use Zend\Db\TableGateway\TableGateway;
8
-use Zend\Db\Sql\Predicate\Expression;
9 7
 use Zend\Paginator\Adapter\DbSelect;
10 8
 use Zend\Paginator\Paginator;
11 9
 use Zend\Crypt\Password\Bcrypt;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
      * Update or Insert user.
107 107
      *
108 108
      * @param Array $data  Data from POST
109
-     * @param null $userId UUID of user if we want to edit or 0 to add new user
109
+     * @param integer $userId UUID of user if we want to edit or 0 to add new user
110 110
      * @throws \Exception
111 111
      */
112 112
     public function save($data, $userId = 0)
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
     {
53 53
         $user = $this->adminUsersMapper->getByEmail($email);
54 54
 
55
-        if(!$user){
55
+        if (!$user) {
56 56
             throw new \Exception('User does not exist.');
57 57
         }
58 58
 
59
-        if(!$this->crypt->verify($password, $user->password)){
59
+        if (!$this->crypt->verify($password, $user->password)) {
60 60
             throw new \Exception('Password does not match.');
61 61
         }
62 62
 
63
-        if($user->status != 1){
63
+        if ($user->status != 1) {
64 64
             throw new \Exception('User is not active.');
65 65
         }
66 66
 
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
     public function save($data, $userId = 0)
113 113
     {
114 114
         //@todo Validate data
115
-        if($data['password'] == ''){
116
-            unset($data['password']);
115
+        if ($data[ 'password' ] == '') {
116
+            unset($data[ 'password' ]);
117 117
         }
118
-        else{
119
-            $data['password'] = $this->crypt->create($data['password']);
118
+        else {
119
+            $data[ 'password' ] = $this->crypt->create($data[ 'password' ]);
120 120
         }
121 121
 
122
-        if($userId){
123
-            $this->adminUsersMapper->update($data, ['admin_user_uuid' => $userId]);
122
+        if ($userId) {
123
+            $this->adminUsersMapper->update($data, [ 'admin_user_uuid' => $userId ]);
124 124
         }
125
-        else{
126
-            $data['admin_user_uuid'] = Uuid::uuid1()->toString();
125
+        else {
126
+            $data[ 'admin_user_uuid' ] = Uuid::uuid1()->toString();
127 127
             $this->adminUsersMapper->insert($data);
128 128
         }
129 129
     }
@@ -136,6 +136,6 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function delete($userId)
138 138
     {
139
-        return (bool)$this->adminUsersMapper->delete(['admin_user_uuid' => $userId]);
139
+        return (bool) $this->adminUsersMapper->delete([ 'admin_user_uuid' => $userId ]);
140 140
     }
141 141
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -114,15 +114,13 @@
 block discarded – undo
114 114
         //@todo Validate data
115 115
         if($data['password'] == ''){
116 116
             unset($data['password']);
117
-        }
118
-        else{
117
+        } else{
119 118
             $data['password'] = $this->crypt->create($data['password']);
120 119
         }
121 120
 
122 121
         if($userId){
123 122
             $this->adminUsersMapper->update($data, ['admin_user_uuid' => $userId]);
124
-        }
125
-        else{
123
+        } else{
126 124
             $data['admin_user_uuid'] = Uuid::uuid1()->toString();
127 125
             $this->adminUsersMapper->insert($data);
128 126
         }
Please login to merge, or discard this patch.
data/phinx/migrations/20160908142829_admin_users.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 {
7 7
     public function up()
8 8
     {
9
-        $this->table('admin_users', ['id' => false, 'primary_key' => 'admin_user_uuid'])
10
-            ->addColumn('admin_user_uuid', 'binary', ['limit' => 16])
9
+        $this->table('admin_users', [ 'id' => false, 'primary_key' => 'admin_user_uuid' ])
10
+            ->addColumn('admin_user_uuid', 'binary', [ 'limit' => 16 ])
11 11
             ->addColumn('first_name', 'text')
12 12
             ->addColumn('last_name', 'text')
13
-            ->addColumn('email', 'string', ['limit' => 128])
14
-            ->addColumn('password', 'char', ['limit' => 60])
15
-            ->addColumn('status', 'integer', ['default' => 0])// 0 => not active, 1 = active
16
-            ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
17
-            ->addColumn('last_login', 'datetime', ['null' => true])
18
-            ->addIndex(['email'], ['name' => 'email_INDEX'])
13
+            ->addColumn('email', 'string', [ 'limit' => 128 ])
14
+            ->addColumn('password', 'char', [ 'limit' => 60 ])
15
+            ->addColumn('status', 'integer', [ 'default' => 0 ])// 0 => not active, 1 = active
16
+            ->addColumn('created_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ])
17
+            ->addColumn('last_login', 'datetime', [ 'null' => true ])
18
+            ->addIndex([ 'email' ], [ 'name' => 'email_INDEX' ])
19 19
             ->create();
20 20
 
21 21
         $faker = Faker\Factory::create();
22 22
         $count = rand(100, 150);
23
-        for($i = 0; $i < $count; $i++){
23
+        for ($i = 0; $i < $count; $i++) {
24 24
             $data = [
25 25
                 'admin_user_uuid' => $faker->uuid,
26 26
                 'email'           => $faker->email,
27 27
                 'first_name'      => $faker->firstName,
28 28
                 'last_name'       => $faker->lastName,
29
-                'password'        => '$2y$10$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK',//password = testtest
29
+                'password'        => '$2y$10$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK', //password = testtest
30 30
                 'status'          => rand(0, 1),
31 31
                 'last_login'      => rand(0, 10) === 7 ? null : $faker->dateTimeBetween('-10 days', 'now')->format('Y-m-d H:i:s'),
32 32
                 'created_at'      => $faker->dateTimeBetween('-20 days', '-10 days')->format('Y-m-d H:i:s'),
Please login to merge, or discard this patch.
config/autoload/routes.global.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
             'name'            => 'home',
25 25
             'path'            => '/',
26 26
             'middleware'      => Web\Action\IndexAction::class,
27
-            'allowed_methods' => ['GET'],
27
+            'allowed_methods' => [ 'GET' ],
28 28
         ],
29 29
         [
30 30
             'name'       => 'about',
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
             'name'            => 'api.ping',
41 41
             'path'            => '/api/ping',
42 42
             'middleware'      => Web\Action\PingAction::class,
43
-            'allowed_methods' => ['GET'],
43
+            'allowed_methods' => [ 'GET' ],
44 44
         ],
45 45
         [
46 46
             'name'            => 'auth',
47 47
             'path'            => '/auth/:action',
48 48
             'middleware'      => Admin\Controller\AuthController::class,
49
-            'allowed_methods' => ['GET', 'POST'],
49
+            'allowed_methods' => [ 'GET', 'POST' ],
50 50
         ],
51 51
 
52 52
         // Admin
@@ -54,31 +54,31 @@  discard block
 block discarded – undo
54 54
             'name'            => 'admin',
55 55
             'path'            => '/admin',
56 56
             'middleware'      => Admin\Action\IndexAction::class,
57
-            'allowed_methods' => ['GET'],
57
+            'allowed_methods' => [ 'GET' ],
58 58
         ],
59 59
         [
60 60
             'name'            => 'admin.users',
61 61
             'path'            => '/admin/users',
62 62
             'middleware'      => Admin\Controller\UserController::class,
63
-            'allowed_methods' => ['GET']
63
+            'allowed_methods' => [ 'GET' ]
64 64
         ],
65 65
         [
66 66
             'name'            => 'admin.users.action',
67 67
             'path'            => '/admin/users/:action/:id',
68 68
             'middleware'      => Admin\Controller\UserController::class,
69
-            'allowed_methods' => ['GET', 'POST']
69
+            'allowed_methods' => [ 'GET', 'POST' ]
70 70
         ],
71 71
         [
72 72
             'name'            => 'admin.tags',
73 73
             'path'            => '/admin/tags',
74 74
             'middleware'      => Admin\Controller\TagController::class,
75
-            'allowed_methods' => ['GET'],
75
+            'allowed_methods' => [ 'GET' ],
76 76
         ],
77 77
         [
78 78
             'name'            => 'admin.posts',
79 79
             'path'            => '/admin/posts',
80 80
             'middleware'      => Admin\Controller\PostController::class,
81
-            'allowed_methods' => ['GET'],
81
+            'allowed_methods' => [ 'GET' ],
82 82
         ],
83 83
     ],
84 84
 ];
Please login to merge, or discard this patch.
src/Core/Mapper/AdminUsersMapper.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
     public function get($id)
33 33
     {
34
-        return $this->select(['admin_user_uuid' => $id])->current();
34
+        return $this->select([ 'admin_user_uuid' => $id ])->current();
35 35
     }
36 36
 
37 37
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function getByEmail(string $email)
44 44
     {
45
-        return $this->select(['email' => $email])->current();
45
+        return $this->select([ 'email' => $email ])->current();
46 46
     }
47 47
 
48 48
     /**
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function updateLogin(string $uuid) : int
55 55
     {
56
-        return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_uuid' => $uuid]);
56
+        return $this->update([ 'last_login' => date('Y-m-d H:i:s') ], [ 'admin_user_uuid' => $uuid ]);
57 57
     }
58 58
 
59 59
     public function getPaginationSelect($userId)
60 60
     {
61
-        $select = $this->getSql()->select()->order(['created_at' => 'desc']);
61
+        $select = $this->getSql()->select()->order([ 'created_at' => 'desc' ]);
62 62
 
63 63
         $select->where->notEqualTo('admin_user_uuid', $userId);
64 64
 
Please login to merge, or discard this patch.
src/Admin/Controller/UserController.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
     {
65 65
         $user   = $this->session->getStorage()->user;
66 66
         $params = $this->request->getQueryParams();
67
-        $page   = isset($params['page']) ? $params['page'] : self::DEFAUTL_PAGE;
68
-        $limit  = isset($params['limit']) ? $params['limit'] : self::DEFAUTL_LIMIT;
67
+        $page   = isset($params[ 'page' ]) ? $params[ 'page' ] : self::DEFAUTL_PAGE;
68
+        $limit  = isset($params[ 'limit' ]) ? $params[ 'limit' ] : self::DEFAUTL_LIMIT;
69 69
 
70 70
         //$filter = [
71 71
         //    'first_name' => isset($params['first_name']) ? $params['first_name'] : '',
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
         $adminUsers = $this->adminUserService->getPagination($page, $limit, $user->admin_user_uuid);
76 76
 
77
-        return new HtmlResponse($this->template->render('admin::user/index', ['list' => $adminUsers]));
77
+        return new HtmlResponse($this->template->render('admin::user/index', [ 'list' => $adminUsers ]));
78 78
     }
79 79
 
80 80
     /**
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
         $userId = $this->request->getAttribute('id');
88 88
         $user   = $this->adminUserService->getUser($userId);
89 89
 
90
-        return new HtmlResponse($this->template->render('admin::user/edit', ['user' => $user]));
90
+        return new HtmlResponse($this->template->render('admin::user/edit', [ 'user' => $user ]));
91 91
     }
92 92
 
93 93
     public function doedit()
94 94
     {
95
-        try{
95
+        try {
96 96
             $userId = $this->request->getAttribute('id');
97 97
             $data   = $this->request->getParsedBody();
98 98
 
@@ -100,23 +100,23 @@  discard block
 block discarded – undo
100 100
 
101 101
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
102 102
         }
103
-        catch(\Exception $e){
103
+        catch (\Exception $e) {
104 104
             return $this->response->withStatus(302)->withHeader(
105 105
                 'Location',
106
-                $this->router->generateUri('admin.users.action', ['action' => 'edit', 'id' => $userId])
106
+                $this->router->generateUri('admin.users.action', [ 'action' => 'edit', 'id' => $userId ])
107 107
             );
108 108
         }
109 109
     }
110 110
 
111 111
     public function delete()
112 112
     {
113
-        try{
113
+        try {
114 114
             $userId = $this->request->getAttribute('id');
115 115
             $this->adminUserService->delete($userId);
116 116
 
117 117
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
118 118
         }
119
-        catch(\Exception $e){
119
+        catch (\Exception $e) {
120 120
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
121 121
         }
122 122
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -99,8 +99,7 @@  discard block
 block discarded – undo
99 99
             $this->adminUserService->save($data, $userId);
100 100
 
101 101
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
102
-        }
103
-        catch(\Exception $e){
102
+        } catch(\Exception $e){
104 103
             return $this->response->withStatus(302)->withHeader(
105 104
                 'Location',
106 105
                 $this->router->generateUri('admin.users.action', ['action' => 'edit', 'id' => $userId])
@@ -115,8 +114,7 @@  discard block
 block discarded – undo
115 114
             $this->adminUserService->delete($userId);
116 115
 
117 116
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
118
-        }
119
-        catch(\Exception $e){
117
+        } catch(\Exception $e){
120 118
             return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.users'));
121 119
         }
122 120
     }
Please login to merge, or discard this patch.