Passed
Push — main ( b29b0b...aea47e )
by Roberto
12:37
created
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/Controller/BaseController.php 1 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/Boson/Model.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         if (!isset(static::$tableName)) {
102 102
             $class = new \ReflectionClass(get_class($this));
103 103
             try {
104
-                $className =  explode("\\", $class->getName());
104
+                $className = explode("\\", $class->getName());
105 105
                 static::$tableName = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', end($className)));
106 106
             } catch (\Exception $e) {
107 107
                 throw new Exceptions\TableNameNotSetException($class);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                         $this->pkName = $maybeField->getName();
140 140
 
141 141
                         // If column name is not set, use field name
142
-                        if($field->db_column() == "") {
142
+                        if ($field->db_column() == "") {
143 143
                             $field->set_db_column($maybeField->getName());
144 144
                         }
145 145
                     }
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
                 elseif ($fieldType->getName() == DataTypes\ForeignKey::class) {
151 151
                     $this->foreignKeys[$maybeField->getName()] = $field;
152 152
                     // If column name is not set, build it as {fieldName}_{parentPrimaryKeyName}
153
-                    if($field->db_column() == "") {
153
+                    if ($field->db_column() == "") {
154 154
                         $props = (new \ReflectionClass($field->parent))->getProperties(\ReflectionProperty::IS_PROTECTED);
155 155
                         $parentPkName = "";
156
-                        foreach($props as $prop) {
156
+                        foreach ($props as $prop) {
157 157
                             $attributes = $prop->getAttributes(DataTypes\PrimaryKey::class);
158
-                            if(count($attributes)) {
158
+                            if (count($attributes)) {
159 159
                                 $parentPkName = $prop->getName();
160 160
                             }
161 161
                         }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
                     $this->fields[$maybeField->getName()] = $field;
177 177
 
178 178
                     // If column name is not set, use field name
179
-                    if($field->db_column() == "") {
179
+                    if ($field->db_column() == "") {
180 180
                         $field->set_db_column($maybeField->getName());
181 181
                     }
182 182
                     $this->db_columns[$maybeField->getName()] = $field->db_column();
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             if (is_subclass_of(($attribute->getName()), DataTypes\Field::class)) {
243 243
                 // A field should have only one field type
244 244
                 if (is_null($fieldType)) {
245
-                    $fieldType =  $attribute;
245
+                    $fieldType = $attribute;
246 246
                 } else {
247 247
                     throw new Exceptions\MultipleFieldAttributeException($prop);
248 248
                 }
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
     private function checkFieldsAreProtected()
266 266
     {
267 267
         $properties = (new \ReflectionClass(get_class($this)))->getProperties(
268
-            \ReflectionProperty::IS_PUBLIC |
269
-            \ReflectionProperty::IS_READONLY |
268
+            \ReflectionProperty::IS_PUBLIC|
269
+            \ReflectionProperty::IS_READONLY|
270 270
             \ReflectionProperty::IS_STATIC
271 271
         );
272 272
         foreach ($properties as $prop) {
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
             return $parent;
302 302
         } elseif ($property == $this->pkName) {
303 303
             return $this->getPk();
304
-        } elseif($this->isReverseForeignKey($property)) {
304
+        } elseif ($this->isReverseForeignKey($property)) {
305 305
             $child = $this->reverseForeignKeys[$property]->child;
306 306
             $arguments = [
307 307
                 $this->reverseForeignKeys[$property]->foreignKey => $this
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 $this->$property = $value;
338 338
             }
339 339
         } elseif (array_key_exists($property, $this->foreignKeys)) {
340
-            if(is_null($value)){
340
+            if (is_null($value)) {
341 341
                 $this->$property = $value;
342 342
                 $this->editedFields[] = $property;
343 343
                 $this->editedFields = array_unique($this->editedFields);
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         if (array_key_exists($field, $this->fields)) {
596 596
             return $this->$field;
597 597
         } elseif (array_key_exists($field, $this->foreignKeys)) {
598
-            if(is_null($this->$field)) return NULL;
598
+            if (is_null($this->$field)) return NULL;
599 599
             return ($this->$field)->getPk();
600 600
         }
601 601
     }
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
      */
613 613
     public static function get(...$filters): Model|bool
614 614
     {
615
-        if ((count($filters) == 1) && array_key_first($filters)  == 0) {
615
+        if ((count($filters) == 1) && array_key_first($filters) == 0) {
616 616
             $filters = array((new static())->pkName => $filters[0]);
617 617
         }
618 618
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 $this->$property = $value;
338 338
             }
339 339
         } elseif (array_key_exists($property, $this->foreignKeys)) {
340
-            if(is_null($value)){
340
+            if(is_null($value)) {
341 341
                 $this->$property = $value;
342 342
                 $this->editedFields[] = $property;
343 343
                 $this->editedFields = array_unique($this->editedFields);
@@ -595,7 +595,9 @@  discard block
 block discarded – undo
595 595
         if (array_key_exists($field, $this->fields)) {
596 596
             return $this->$field;
597 597
         } elseif (array_key_exists($field, $this->foreignKeys)) {
598
-            if(is_null($this->$field)) return NULL;
598
+            if(is_null($this->$field)) {
599
+                return NULL;
600
+            }
599 601
             return ($this->$field)->getPk();
600 602
         }
601 603
     }
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.
src/Boson/DataTypes/DateField.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 
4 4
 #[\Attribute]
5 5
 class DateField extends Field{
6
-  public function __construct(...$args){
6
+    public function __construct(...$args){
7 7
     parent::__construct(...$args);
8
-  }
8
+    }
9 9
 
10
-  public function validate($value){
10
+    public function validate($value){
11 11
     if (!preg_match("/\d{4}-\d{2}-\d{2}/", $value)) return false;
12 12
     return parent::validate($value);
13
-  }
13
+    }
14 14
 
15 15
 }
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 namespace Lepton\Boson\DataTypes;
3 3
 
4 4
 #[\Attribute]
5
-class DateField extends Field{
6
-  public function __construct(...$args){
5
+class DateField extends Field {
6
+  public function __construct(...$args) {
7 7
     parent::__construct(...$args);
8 8
   }
9 9
 
10
-  public function validate($value){
10
+  public function validate($value) {
11 11
     if (!preg_match("/\d{4}-\d{2}-\d{2}/", $value)) return false;
12 12
     return parent::validate($value);
13 13
   }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@
 block discarded – undo
8 8
   }
9 9
 
10 10
   public function validate($value){
11
-    if (!preg_match("/\d{4}-\d{2}-\d{2}/", $value)) return false;
11
+    if (!preg_match("/\d{4}-\d{2}-\d{2}/", $value)) {
12
+        return false;
13
+    }
12 14
     return parent::validate($value);
13 15
   }
14 16
 
Please login to merge, or discard this patch.
src/Boson/DataTypes/NumberField.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@
 block discarded – undo
3 3
 
4 4
 #[\Attribute]
5 5
 class NumberField extends Field{
6
-  public function __construct(mixed ...$options){
6
+    public function __construct(mixed ...$options){
7 7
     parent::__construct(...$options);
8
-  }
8
+    }
9 9
 
10
-  public function validate($value){
10
+    public function validate($value){
11 11
     if(!is_numeric($value)) return false;
12 12
     return parent::validate($value);
13
-  }
13
+    }
14 14
 }
15 15
\ 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,13 +2,13 @@
 block discarded – undo
2 2
 namespace Lepton\Boson\DataTypes;
3 3
 
4 4
 #[\Attribute]
5
-class NumberField extends Field{
6
-  public function __construct(mixed ...$options){
5
+class NumberField extends Field {
6
+  public function __construct(mixed ...$options) {
7 7
     parent::__construct(...$options);
8 8
   }
9 9
 
10
-  public function validate($value){
11
-    if(!is_numeric($value)) return false;
10
+  public function validate($value) {
11
+    if (!is_numeric($value)) return false;
12 12
     return parent::validate($value);
13 13
   }
14 14
 }
15 15
\ 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
@@ -8,7 +8,9 @@
 block discarded – undo
8 8
   }
9 9
 
10 10
   public function validate($value){
11
-    if(!is_numeric($value)) return false;
11
+    if(!is_numeric($value)) {
12
+        return false;
13
+    }
12 14
     return parent::validate($value);
13 15
   }
14 16
 }
15 17
\ No newline at end of file
Please login to merge, or discard this patch.