Passed
Push — main ( 7f34fc...ff3d68 )
by Roberto
12:26
created
src/Controller/BaseController.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $template  = new Template($path);
22 22
         $template->registerFilter(new SiteFilter());
23 23
 
24
-        if(isset($this->custom_filters)){
24
+        if(isset($this->custom_filters)) {
25 25
             foreach($this->custom_filters as $filter){
26 26
                 $template->registerFilter(new $filter());
27 27
             }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     protected array $custom_filters;
15 15
     public string $baseLink;
16 16
 
17
-    public function url($string){
17
+    public function url($string) {
18 18
         return Application::getDir()."/".$string;
19 19
     }
20 20
 
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
         Liquid::set('INCLUDE_SUFFIX', 'html');
24 24
         Liquid::set('INCLUDE_PREFIX', '');
25 25
         $path = "app/Views";
26
-        $template  = new Template($path);
26
+        $template = new Template($path);
27 27
         $template->registerFilter(new SiteFilter());
28 28
 
29
-        if(isset($this->custom_filters)){
30
-            foreach($this->custom_filters as $filter){
29
+        if (isset($this->custom_filters)) {
30
+            foreach ($this->custom_filters as $filter) {
31 31
                 $template->registerFilter(new $filter());
32 32
             }
33 33
         }
34 34
         $template->parseFile($view);
35
-        $parameters = array_map(function ($x) {
35
+        $parameters = array_map(function($x) {
36 36
             if ($x instanceof QuerySet) {
37 37
                 return $x->do();
38 38
             } else {
Please login to merge, or discard this patch.
src/Authenticator/RBAC/UserInterface.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
     public function hasPermission(PermissionInterface $permission) : bool;
21 21
 
22 22
 
23
-     /**
24
-     * Retrieve the permissions associated with the user's roles.
25
-     *
26
-     * @return array An array of permissions associated with the user's roles.
27
-     */
23
+        /**
24
+         * Retrieve the permissions associated with the user's roles.
25
+         *
26
+         * @return array An array of permissions associated with the user's roles.
27
+         */
28 28
     public function getPermissions() : array;
29 29
 
30 30
 
Please login to merge, or discard this patch.
src/Middleware/RBACMiddleware.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
         $this->rbac_class = $middlewareParams["rbac_class"] ?? throw new \Exception("You have to define a RBAC class");
21 21
 
22 22
         $rbac_interfaces = class_implements($this->rbac_class);
23
-        if(! in_array(\Lepton\Authenticator\RBAC\RBACInterface::class, $rbac_interfaces)) {
23
+        if (!in_array(\Lepton\Authenticator\RBAC\RBACInterface::class, $rbac_interfaces)) {
24 24
                 throw new \Exception("RBAC class has to implement \Lepton\Authenticator\RBAC\RBACInterface");
25 25
         }
26 26
 
27 27
         $this->user_class = $middlewareParams["user_class"] ?? throw new \Exception("You have to define a User class");
28 28
 
29 29
         $user_interfaces = class_implements($this->user_class);
30
-        if(! in_array(\Lepton\Authenticator\RBAC\UserInterface::class, $user_interfaces)) {
30
+        if (!in_array(\Lepton\Authenticator\RBAC\UserInterface::class, $user_interfaces)) {
31 31
                 throw new \Exception("User class has to implement \Lepton\Authenticator\RBAC\UserInterface");
32 32
         }
33 33
 
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
     protected function checkPermissions(string $modifier, mixed ...$params): bool
39 39
     {
40 40
 
41
-        if($modifier == LoginRequired::class) {
41
+        if ($modifier == LoginRequired::class) {
42 42
 
43 43
             $level = isset($params[0]) ? $params[0] : 1;
44 44
             $authenticator = new \Lepton\Authenticator\UserAuthenticator();
45 45
             $loggedIn = $authenticator->isLoggedIn();
46
-            if(! $loggedIn) {
46
+            if (!$loggedIn) {
47 47
                 return false;
48 48
             }
49 49
             $user = $authenticator->getLoggedUser();
50 50
             $num_privileges = $user->privileges->and(livello__gte: $level)->count();
51 51
             return ($num_privileges > 0);
52
-        } elseif($modifier == PermissionRequired::class){
52
+        } elseif ($modifier == PermissionRequired::class) {
53 53
             $user = (new UserAuthenticator)->getLoggedUser();
54 54
             die(print_r($params));
55 55
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
             $user = $authenticator->getLoggedUser();
50 50
             $num_privileges = $user->privileges->and(livello__gte: $level)->count();
51 51
             return ($num_privileges > 0);
52
-        } elseif($modifier == PermissionRequired::class){
52
+        } elseif($modifier == PermissionRequired::class) {
53 53
             $user = (new UserAuthenticator)->getLoggedUser();
54 54
             die(print_r($params));
55 55
         }
Please login to merge, or discard this patch.
src/Http/Response/JSONResponse.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace Lepton\Http\Response;
4 4
 
5
- class JSONResponse extends SuccessResponse
5
+    class JSONResponse extends SuccessResponse
6 6
 {
7 7
 
8 8
     public function __construct(
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
         parent::__construct(headers: ["Content-Type" => "application/json"]);
13 13
     }
14 14
 
15
-    public function sendBody(){
15
+    public function sendBody() {
16 16
         echo json_encode($this->array);
17 17
     }
18 18
 
Please login to merge, or discard this patch.
src/Authenticator/UserAuthenticator.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
             $session_hash = bin2hex(random_bytes(32));
45 45
             $_SESSION['user_id'] = $user->getPk();
46 46
             $_SESSION['session_hash'] = $session_hash;
47
-            if($this->config->login_use_unique_hash) {
47
+            if ($this->config->login_use_unique_hash) {
48 48
                 $hashField = $this->config->hash_field;
49 49
                 $user->$hashField = $session_hash;
50 50
                 $user->save();
51 51
             }
52
-            if(isset($this->config->access_field)){
52
+            if (isset($this->config->access_field)) {
53 53
                 $accessField = $this->config->access_field;
54 54
                 date_default_timezone_set('Europe/Rome');
55
-                $user->$accessField = date('Y-m-d H:i:s', time());;
55
+                $user->$accessField = date('Y-m-d H:i:s', time()); ;
56 56
                 $user->save();
57 57
             }
58 58
             return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         }
102 102
 
103 103
         // Hash the password
104
-        if (! $password) {
104
+        if (!$password) {
105 105
             $password = $this->randomPassword(length: $password_length);
106 106
         }
107 107
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     {
135 135
         if ($this->isLoggedIn()) {
136 136
             if (isset($_SESSION['user_id'])) {
137
-                if(isset($this->config->hash_field)) {
137
+                if (isset($this->config->hash_field)) {
138 138
                     $user = $this->getUserById($_SESSION['user_id']);
139 139
                     $hashField = $this->config->hash_field;
140 140
                     $user->$hashField = "";
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                 $user->$hashField = $session_hash;
50 50
                 $user->save();
51 51
             }
52
-            if(isset($this->config->access_field)){
52
+            if(isset($this->config->access_field)) {
53 53
                 $accessField = $this->config->access_field;
54 54
                 date_default_timezone_set('Europe/Rome');
55 55
                 $user->$accessField = date('Y-m-d H:i:s', time());;
@@ -72,7 +72,8 @@  discard block
 block discarded – undo
72 72
         $user = $this->getUserById($user_id);
73 73
 
74 74
         //$hashField = $this->config->hash_field;
75
-        if (!$user) {// || $user->$hashField !== $_SESSION['session_hash']) {
75
+        if (!$user) {
76
+// || $user->$hashField !== $_SESSION['session_hash']) {
76 77
             return false;
77 78
         }
78 79
 
Please login to merge, or discard this patch.
src/Boson/DataTypes/CharField.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
     public function validate($value)
14 14
     {
15
-        if(strlen($value) > $this->max_length) return false;
15
+        if (strlen($value) > $this->max_length) return false;
16 16
         return parent::validate($value);
17 17
     }
18 18
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@
 block discarded – undo
12 12
 
13 13
     public function validate($value)
14 14
     {
15
-        if(strlen($value) > $this->max_length) return false;
15
+        if(strlen($value) > $this->max_length) {
16
+            return false;
17
+        }
16 18
         return parent::validate($value);
17 19
     }
18 20
 }
Please login to merge, or discard this patch.
src/Boson/DataTypes/Field.php 3 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -4,59 +4,59 @@
 block discarded – undo
4 4
 
5 5
 class Field{
6 6
 
7
-  protected array $default_error_messages = array(
7
+    protected array $default_error_messages = array(
8 8
     "invalid_choice"  => "Value %value is not a valid choice.",
9 9
     "null"            => "This field cannot be null.",
10 10
     "blank"           => "This field cannot be blank.",
11 11
     "unique"          => "A %model_name with this %field_label already exists.",
12 12
     "unique_for"      => "Field %field_label must be unique for fields with same %unique_for."
13
-  );
14
-
15
-  protected array $validation_errors = array();
16
-
17
-  public function __construct(
18
-     protected bool   $null             = false,
19
-     protected bool   $blank            = true,
20
-     protected array  $choices          = array(),
21
-     protected string $db_column        = "",
22
-     protected mixed  $default          = "",
23
-     protected bool   $editable         = true,
24
-     protected array  $error_messages   = array(),
25
-     protected string $help_text        = "",
26
-     protected bool   $primary_key      = false,
27
-     protected bool   $unique           = false,
28
-     protected string $verbose_name     = "",
29
-     protected array  $validators       = array()
13
+    );
14
+
15
+    protected array $validation_errors = array();
16
+
17
+    public function __construct(
18
+        protected bool   $null             = false,
19
+        protected bool   $blank            = true,
20
+        protected array  $choices          = array(),
21
+        protected string $db_column        = "",
22
+        protected mixed  $default          = "",
23
+        protected bool   $editable         = true,
24
+        protected array  $error_messages   = array(),
25
+        protected string $help_text        = "",
26
+        protected bool   $primary_key      = false,
27
+        protected bool   $unique           = false,
28
+        protected string $verbose_name     = "",
29
+        protected array  $validators       = array()
30 30
     )
31
-  {
31
+    {
32 32
     return;
33
-  }
33
+    }
34 34
 
35 35
 
36
-  protected function validate($value){
36
+    protected function validate($value){
37 37
     if (is_null($value) && (!$this->null)) return false;
38 38
     if (empty($value) && (!$this->blank)) return false;
39 39
     if (!empty($this->choices) && !in_array($value, $this->choices)) return false;
40 40
     if (!empty($this->validators)) return $this->validate_with_validators($value);
41 41
 
42 42
     return true;
43
-  }
43
+    }
44 44
 
45 45
 
46
-  private function validate_with_validators($value){
46
+    private function validate_with_validators($value){
47 47
     foreach($this->validators as $validator){
48
-      if (!$validator($value)) return false;
48
+        if (!$validator($value)) return false;
49 49
     }
50 50
     return true;
51
-  }
51
+    }
52 52
 
53 53
 
54 54
 
55
-  public function db_column(): string{
55
+    public function db_column(): string{
56 56
     return $this->db_column;
57
-  }
57
+    }
58 58
 
59
-  public function set_db_column(string $column_name): void{
59
+    public function set_db_column(string $column_name): void{
60 60
     $this->db_column = $column_name;
61
-  }
61
+    }
62 62
 }
63 63
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace Lepton\Boson\DataTypes;
3 3
 
4 4
 
5
-class Field{
5
+class Field {
6 6
 
7 7
   protected array $default_error_messages = array(
8 8
     "invalid_choice"  => "Value %value is not a valid choice.",
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
   }
34 34
 
35 35
 
36
-  protected function validate($value){
36
+  protected function validate($value) {
37 37
     if (is_null($value) && (!$this->null)) return false;
38 38
     if (empty($value) && (!$this->blank)) return false;
39 39
     if (!empty($this->choices) && !in_array($value, $this->choices)) return false;
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
   }
44 44
 
45 45
 
46
-  private function validate_with_validators($value){
47
-    foreach($this->validators as $validator){
46
+  private function validate_with_validators($value) {
47
+    foreach ($this->validators as $validator) {
48 48
       if (!$validator($value)) return false;
49 49
     }
50 50
     return true;
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,10 +34,18 @@  discard block
 block discarded – undo
34 34
 
35 35
 
36 36
   protected function validate($value){
37
-    if (is_null($value) && (!$this->null)) return false;
38
-    if (empty($value) && (!$this->blank)) return false;
39
-    if (!empty($this->choices) && !in_array($value, $this->choices)) return false;
40
-    if (!empty($this->validators)) return $this->validate_with_validators($value);
37
+    if (is_null($value) && (!$this->null)) {
38
+        return false;
39
+    }
40
+    if (empty($value) && (!$this->blank)) {
41
+        return false;
42
+    }
43
+    if (!empty($this->choices) && !in_array($value, $this->choices)) {
44
+        return false;
45
+    }
46
+    if (!empty($this->validators)) {
47
+        return $this->validate_with_validators($value);
48
+    }
41 49
 
42 50
     return true;
43 51
   }
@@ -45,7 +53,9 @@  discard block
 block discarded – undo
45 53
 
46 54
   private function validate_with_validators($value){
47 55
     foreach($this->validators as $validator){
48
-      if (!$validator($value)) return false;
56
+      if (!$validator($value)) {
57
+          return false;
58
+      }
49 59
     }
50 60
     return true;
51 61
   }
Please login to merge, or discard this patch.
src/Boson/DataTypes/TextField.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 
8 8
 
9
-  public function __construct(private $max_length = 128, ...$options ){
10
-     parent::__construct(...$options);
9
+    public function __construct(private $max_length = 128, ...$options ){
10
+        parent::__construct(...$options);
11 11
 
12
-  }
12
+    }
13 13
 
14
-  public function validate($value){
14
+    public function validate($value){
15 15
     if(strlen($value) > $this->max_length) return false;
16 16
     return parent::validate($value);
17
-  }
17
+    }
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,17 +2,17 @@
 block discarded – undo
2 2
 namespace Lepton\Boson\DataTypes;
3 3
 
4 4
 #[\Attribute]
5
-class TextField extends Field{
5
+class TextField extends Field {
6 6
 
7 7
 
8 8
 
9
-  public function __construct(private $max_length = 128, ...$options ){
9
+  public function __construct(private $max_length = 128, ...$options) {
10 10
      parent::__construct(...$options);
11 11
 
12 12
   }
13 13
 
14
-  public function validate($value){
15
-    if(strlen($value) > $this->max_length) return false;
14
+  public function validate($value) {
15
+    if (strlen($value) > $this->max_length) return false;
16 16
     return parent::validate($value);
17 17
   }
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@
 block discarded – undo
12 12
   }
13 13
 
14 14
   public function validate($value){
15
-    if(strlen($value) > $this->max_length) return false;
15
+    if(strlen($value) > $this->max_length) {
16
+        return false;
17
+    }
16 18
     return parent::validate($value);
17 19
   }
18 20
 }
19 21
\ No newline at end of file
Please login to merge, or discard this patch.
src/Boson/DataTypes/ManyToMany.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@
 block discarded – undo
14 14
 
15 15
     public function validate($value)
16 16
     {
17
-        if (!is_a($value, $this->child)) return false;
17
+        if (!is_a($value, $this->child)) {
18
+            return false;
19
+        }
18 20
         return parent::validate($value);
19 21
     }
20 22
 }
Please login to merge, or discard this patch.