Completed
Push — master ( 9f8480...602ed2 )
by Helmut
04:40
created
src/Form.php 3 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      */
358 358
     public function completed($name = null)
359 359
     {
360
-        if($this->submitted($name) && $this->valid()) {
360
+        if ($this->submitted($name) && $this->valid()) {
361 361
             $this->broadcast('completed');
362 362
             return true;
363 363
         }
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         $errors = [];
498 498
 
499 499
         foreach ($this->fields as $field) {
500
-            foreach($field->errors() as $error) {
500
+            foreach ($field->errors() as $error) {
501 501
                 $errors[] = $error;
502 502
             }
503 503
         }
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
     {
620 620
         $config = $this->templateConfig($template);
621 621
 
622
-        if ( isset($config['plugins']) && is_array($config['plugins'])) {
623
-            foreach($config['plugins'] as $plugin) {
622
+        if (isset($config['plugins']) && is_array($config['plugins'])) {
623
+            foreach ($config['plugins'] as $plugin) {
624 624
                 $this->addPlugin($plugin);
625 625
             }
626 626
         }
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
     {
637 637
         $config = $this->templateConfig($template);
638 638
 
639
-        if ( isset($config['plugins']) && is_array($config['plugins'])) {
640
-            foreach($config['plugins'] as $plugin) {
639
+        if (isset($config['plugins']) && is_array($config['plugins'])) {
640
+            foreach ($config['plugins'] as $plugin) {
641 641
                 $this->removePlugin($plugin);
642 642
             }
643 643
         }
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             foreach ($field->errors() as $error => $parameters) {
675 675
 
676 676
                 if ($error == 'userDefined') {
677
-                    foreach($parameters as $message) {
677
+                    foreach ($parameters as $message) {
678 678
                         $properties['errors'][] = ['error' => $message];
679 679
                     }
680 680
                 } else {
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 
684 684
                     $message = $this->translate($error, $field);
685 685
 
686
-                    foreach($parameters as $key => $value) {
686
+                    foreach ($parameters as $key => $value) {
687 687
                         if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value;
688 688
                         if (is_array($value)) $value = implode(', ', $value);
689 689
                         $message = str_replace('['.$key.']', $value, $message);
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
      */
931 931
     private function broadcast($event, $params = []) 
932 932
     {
933
-        foreach($this->plugins as $plugin) {
933
+        foreach ($this->plugins as $plugin) {
934 934
             $plugin->event($this, $event, $params);
935 935
         }
936 936
     }
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
     {
1079 1079
         if ( ! method_exists($this, $method))
1080 1080
         {
1081
-            if ( $this->typeExists($method)) {
1081
+            if ($this->typeExists($method)) {
1082 1082
                 return $this->addField($method, array_shift($parameters));
1083 1083
             }
1084 1084
         }
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -259,7 +259,9 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public function fields($names = null)
261 261
     {
262
-        if (is_null($names)) return $this->fields;
262
+        if (is_null($names)) {
263
+            return $this->fields;
264
+        }
263 265
 
264 266
         return array_filter($this->fields, function($field) use ($names) {
265 267
             return array_key_exists($field->name, $names);
@@ -442,7 +444,9 @@  discard block
 block discarded – undo
442 444
      */
443 445
     public function addNamespaceForClass($class)
444 446
     {
445
-        if (is_object($class)) $class = get_class($class);
447
+        if (is_object($class)) {
448
+            $class = get_class($class);
449
+        }
446 450
 
447 451
         $reflector = new \ReflectionClass($class);
448 452
 
@@ -477,7 +481,9 @@  discard block
 block discarded – undo
477 481
         $class = '\\Fields\\'.ucwords($class).'\\'.ucwords($class);
478 482
 
479 483
         foreach ($this->namespaces as $namespace) {
480
-            if (class_exists($namespace.$class)) return $namespace.$class;
484
+            if (class_exists($namespace.$class)) {
485
+                return $namespace.$class;
486
+            }
481 487
         }
482 488
     }
483 489
 
@@ -490,9 +496,13 @@  discard block
 block discarded – undo
490 496
      */
491 497
     public function errors($name = null)
492 498
     {
493
-        if ($this->submitted()) $this->validate();
499
+        if ($this->submitted()) {
500
+            $this->validate();
501
+        }
494 502
 
495
-        if ( ! is_null($name)) $this->field($name)->errors();
503
+        if ( ! is_null($name)) {
504
+            $this->field($name)->errors();
505
+        }
496 506
 
497 507
         $errors = [];
498 508
 
@@ -684,8 +694,12 @@  discard block
 block discarded – undo
684 694
                     $message = $this->translate($error, $field);
685 695
 
686 696
                     foreach($parameters as $key => $value) {
687
-                        if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value;
688
-                        if (is_array($value)) $value = implode(', ', $value);
697
+                        if (is_object($value) && method_exists($value, '__toString')) {
698
+                            $value = (string) $value;
699
+                        }
700
+                        if (is_array($value)) {
701
+                            $value = implode(', ', $value);
702
+                        }
689 703
                         $message = str_replace('['.$key.']', $value, $message);
690 704
                     }
691 705
                     $properties['errors'][] = ['error' => $message];
@@ -705,7 +719,9 @@  discard block
 block discarded – undo
705 719
      */
706 720
     public function renderField($field, $properties = null) 
707 721
     {   
708
-        if (is_null($properties)) $properties = $this->fieldProperties($field);
722
+        if (is_null($properties)) {
723
+            $properties = $this->fieldProperties($field);
724
+        }
709 725
 
710 726
         return $this->renderTemplate($field->type, $properties, $field);
711 727
     }
@@ -719,7 +735,9 @@  discard block
 block discarded – undo
719 735
      */
720 736
     public function renderFieldErrors($field, $properties = null) 
721 737
     {   
722
-        if (is_null($properties)) $properties = $this->fieldProperties($field);
738
+        if (is_null($properties)) {
739
+            $properties = $this->fieldProperties($field);
740
+        }
723 741
 
724 742
         return $this->renderTemplate('errors', $properties, $field);
725 743
     }   
@@ -736,9 +754,13 @@  discard block
 block discarded – undo
736 754
 
737 755
         $this->setValues();
738 756
 
739
-        if ($this->submitted()) $this->validate();
757
+        if ($this->submitted()) {
758
+            $this->validate();
759
+        }
740 760
 
741
-        if ( ! is_null($template)) $this->setTemplate($template);
761
+        if ( ! is_null($template)) {
762
+            $this->setTemplate($template);
763
+        }
742 764
 
743 765
         $properties = [];
744 766
         $properties['id'] = $this->id;
@@ -992,7 +1014,9 @@  discard block
 block discarded – undo
992 1014
      */
993 1015
     public function pathForClass($class)
994 1016
     {
995
-        if (is_object($class)) $class = get_class($class);
1017
+        if (is_object($class)) {
1018
+            $class = get_class($class);
1019
+        }
996 1020
 
997 1021
         $reflector = new \ReflectionClass($class);
998 1022
         $path = dirname($reflector->getFileName()); 
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      * Check if a type exists.
456 456
      *
457 457
      * @param  string  $type
458
-     * @return string
458
+     * @return boolean
459 459
      */
460 460
     public function typeExists($type)
461 461
     {
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
      *
1071 1071
      * @param  string  $method
1072 1072
      * @param  array  $parameters
1073
-     * @return mixed
1073
+     * @return Fields\Field|null
1074 1074
      */
1075 1075
     public function __call($method, $parameters)
1076 1076
     {
Please login to merge, or discard this patch.
src/Request.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 block discarded – undo
4 4
 
5 5
 interface Request {
6 6
 	
7
-	/**
7
+    /**
8 8
      * Fetch all values from the request.
9 9
      *
10 10
      * @return array
11 11
      */
12
-	public function all();
12
+    public function all();
13 13
 
14
-	/**
14
+    /**
15 15
      * Fetch a value from the request matching provided key.
16 16
      *
17 17
      * @var string
18 18
      * @return mixed
19 19
      */
20
-	public function get($key);
20
+    public function get($key);
21 21
 
22
-	/**
22
+    /**
23 23
      * Return array of csrf template properties.
24 24
      *
25 25
      * @return array
26 26
      */
27
-	public function csrf();	
27
+    public function csrf();	
28 28
 
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
src/templates/foundation/config.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3 3
 return [
4
-	'plugins' => [
5
-		'feedback',
6
-	],
4
+    'plugins' => [
5
+        'feedback',
6
+    ],
7 7
 ];
8 8
\ No newline at end of file
Please login to merge, or discard this patch.
src/Fields/Dropdown/Dropdown.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.
src/Fields/Text/Text.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.
src/Fields/ParagraphText/ParagraphText.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.
src/Fields/Email/Email.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.
src/Renderer.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -4,140 +4,140 @@
 block discarded – undo
4 4
 
5 5
 class Renderer {
6 6
 	
7
- 	/**
8
-     * Array of engine definitions using
9
-     * file extension as key.
10
-     * 
11
-     * @var array
12
-     */
13
-	protected $engines = [
14
-		'.mustache.php' => 'Helmut\Forms\Engines\Mustache',
15
-		'.twig.php' => 'Helmut\Forms\Engines\Twig',
16
-		'.blade.php' => 'Helmut\Forms\Engines\Blade',
17
-	];
18
-
19
- 	/**
20
-     * Cache of running engines.
21
-     *
22
-     * @var array
23
-     */
24
-	protected $running = [];
25
-
26
- 	/**
27
-     * Cache of template files.
28
-     *
29
-     * @var array
30
-     */
31
-	protected $templates = [];
32
-
33
-	/**
7
+        /**
8
+         * Array of engine definitions using
9
+         * file extension as key.
10
+         * 
11
+         * @var array
12
+         */
13
+    protected $engines = [
14
+        '.mustache.php' => 'Helmut\Forms\Engines\Mustache',
15
+        '.twig.php' => 'Helmut\Forms\Engines\Twig',
16
+        '.blade.php' => 'Helmut\Forms\Engines\Blade',
17
+    ];
18
+
19
+        /**
20
+         * Cache of running engines.
21
+         *
22
+         * @var array
23
+         */
24
+    protected $running = [];
25
+
26
+        /**
27
+         * Cache of template files.
28
+         *
29
+         * @var array
30
+         */
31
+    protected $templates = [];
32
+
33
+    /**
34 34
      * Add a new engine implementation.
35 35
      *
36
-	 * @param  string  $extension
37
-	 * @param  string  $class
36
+     * @param  string  $extension
37
+     * @param  string  $class
38 38
      * @return void
39 39
      */
40
-	public function addEngine($extension, $class)
41
-	{
42
-		array_unshift($this->engines, [$extension => $class]);
43
-	}
40
+    public function addEngine($extension, $class)
41
+    {
42
+        array_unshift($this->engines, [$extension => $class]);
43
+    }
44 44
 
45
-	/**
45
+    /**
46 46
      * Get an engine implementation.
47 47
      *
48
-	 * @param  string  $key
48
+     * @param  string  $key
49 49
      * @return \Helmut\Forms\Engine
50 50
      */
51
-	public function start($key)
52
-	{
53
-		if ( ! isset($this->running[$key])) {
54
-			$this->running[$key] = new $this->engines[$key];
55
-		}
51
+    public function start($key)
52
+    {
53
+        if ( ! isset($this->running[$key])) {
54
+            $this->running[$key] = new $this->engines[$key];
55
+        }
56 56
 
57
-		return $this->running[$key];
58
-	}
57
+        return $this->running[$key];
58
+    }
59 59
 
60
-	/**
60
+    /**
61 61
      * Get engine file extensions.
62 62
      *
63 63
      * @return array
64 64
      */
65
-	public function extensions()
66
-	{
67
-		return array_keys($this->engines);
68
-	}
65
+    public function extensions()
66
+    {
67
+        return array_keys($this->engines);
68
+    }
69 69
 
70
-	/**
70
+    /**
71 71
      * Create a template cache key.
72 72
      *
73
-	 * @param  string  $template
74
-	 * @param  array  $paths
73
+     * @param  string  $template
74
+     * @param  array  $paths
75 75
      * @return string
76 76
      */	
77
-	public function key($template, $paths) 
78
-	{
79
-		return $template.'-'.md5(serialize($paths));
80
-	}
77
+    public function key($template, $paths) 
78
+    {
79
+        return $template.'-'.md5(serialize($paths));
80
+    }
81 81
 
82
-	/**
82
+    /**
83 83
      * Render a template.
84 84
      *
85
-	 * @param  string  $template
86
-	 * @param  array  $properties
87
-	 * @param  array  $paths
85
+     * @param  string  $template
86
+     * @param  array  $properties
87
+     * @param  array  $paths
88 88
      * @return string
89 89
      */
90
-	public function render($template, $properties, $paths)
91
-	{
92
-		if ($this->has($template, $paths)) {
90
+    public function render($template, $properties, $paths)
91
+    {
92
+        if ($this->has($template, $paths)) {
93 93
 
94
-			$template = $this->findTemplate($template, $paths);
94
+            $template = $this->findTemplate($template, $paths);
95 95
 
96
-			return $this->start($template['engine'])->render($template['path'], $properties);
97
-		}
98
-	}
96
+            return $this->start($template['engine'])->render($template['path'], $properties);
97
+        }
98
+    }
99 99
 
100
-	/**
100
+    /**
101 101
      * Check if a template exists.
102 102
      *
103
-	 * @param  string  $template
104
-	 * @param  array  $paths
103
+     * @param  string  $template
104
+     * @param  array  $paths
105 105
      * @return boolean
106 106
      */	
107
-	public function has($template, $paths)
108
-	{
109
-		return ! is_null($this->findTemplate($template, $paths));
110
-	}
107
+    public function has($template, $paths)
108
+    {
109
+        return ! is_null($this->findTemplate($template, $paths));
110
+    }
111 111
 
112
-	/**
112
+    /**
113 113
      * Find template file with engine.
114 114
      *
115
-	 * @param  string  $template
116
-	 * @param  array  $paths
115
+     * @param  string  $template
116
+     * @param  array  $paths
117 117
      * @return array
118 118
      */	
119
-	public function findTemplate($template, $paths)
120
-	{
121
-		$key = $this->key($template, $paths);
122
-
123
-		if ( ! isset($this->templates[$key])) {
124
-
125
-			$this->templates[$key] = null;
126
-
127
-			$extensions = $this->extensions();
128
-			foreach ($paths as $path) {
129
-				foreach ($extensions as $extension) {
130
-					if (file_exists($path.$template.$extension)) {
131
-						return $this->templates[$key] = [
132
-							'engine' => $extension, 
133
-							'path' => $path.$template.$extension,
134
-						];
135
-					}
136
-				}
137
-			}
138
-		}
139
-
140
-		return $this->templates[$key];
141
-	}	
119
+    public function findTemplate($template, $paths)
120
+    {
121
+        $key = $this->key($template, $paths);
122
+
123
+        if ( ! isset($this->templates[$key])) {
124
+
125
+            $this->templates[$key] = null;
126
+
127
+            $extensions = $this->extensions();
128
+            foreach ($paths as $path) {
129
+                foreach ($extensions as $extension) {
130
+                    if (file_exists($path.$template.$extension)) {
131
+                        return $this->templates[$key] = [
132
+                            'engine' => $extension, 
133
+                            'path' => $path.$template.$extension,
134
+                        ];
135
+                    }
136
+                }
137
+            }
138
+        }
139
+
140
+        return $this->templates[$key];
141
+    }	
142 142
 
143 143
 }
Please login to merge, or discard this patch.