Completed
Pull Request — 4.0 (#83)
by Marc
06:48
created
src/Mouf/Database/TDBM/MapIterator.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -9,91 +9,91 @@
 block discarded – undo
9 9
  */
10 10
 class MapIterator implements Iterator, \JsonSerializable
11 11
 {
12
-    /**
13
-     * @var Iterator
14
-     */
15
-    protected $iterator;
12
+	/**
13
+	 * @var Iterator
14
+	 */
15
+	protected $iterator;
16 16
 
17
-    /**
18
-     * @var callable Modifies the current item in iterator
19
-     */
20
-    protected $callable;
17
+	/**
18
+	 * @var callable Modifies the current item in iterator
19
+	 */
20
+	protected $callable;
21 21
 
22
-    /**
23
-     * @param $iterator Iterator|array
24
-     * @param $callable callable This can have two parameters
25
-     *
26
-     * @throws TDBMException
27
-     */
28
-    public function __construct($iterator, callable $callable)
29
-    {
30
-        if (is_array($iterator)) {
31
-            $this->iterator = new \ArrayIterator($iterator);
32
-        } elseif (!($iterator instanceof Iterator)) {
33
-            throw new TDBMException('$iterator parameter must be an instance of Iterator');
34
-        } else {
35
-            $this->iterator = $iterator;
36
-        }
22
+	/**
23
+	 * @param $iterator Iterator|array
24
+	 * @param $callable callable This can have two parameters
25
+	 *
26
+	 * @throws TDBMException
27
+	 */
28
+	public function __construct($iterator, callable $callable)
29
+	{
30
+		if (is_array($iterator)) {
31
+			$this->iterator = new \ArrayIterator($iterator);
32
+		} elseif (!($iterator instanceof Iterator)) {
33
+			throw new TDBMException('$iterator parameter must be an instance of Iterator');
34
+		} else {
35
+			$this->iterator = $iterator;
36
+		}
37 37
 
38
-        if ($callable instanceof \Closure) {
39
-            // make sure there's one argument
40
-            $reflection = new \ReflectionObject($callable);
41
-            if ($reflection->hasMethod('__invoke')) {
42
-                $method = $reflection->getMethod('__invoke');
43
-                if ($method->getNumberOfParameters() !== 1) {
44
-                    throw new TDBMException('$callable must accept one and only one parameter.');
45
-                }
46
-            }
47
-        }
38
+		if ($callable instanceof \Closure) {
39
+			// make sure there's one argument
40
+			$reflection = new \ReflectionObject($callable);
41
+			if ($reflection->hasMethod('__invoke')) {
42
+				$method = $reflection->getMethod('__invoke');
43
+				if ($method->getNumberOfParameters() !== 1) {
44
+					throw new TDBMException('$callable must accept one and only one parameter.');
45
+				}
46
+			}
47
+		}
48 48
 
49
-        $this->callable = $callable;
50
-    }
49
+		$this->callable = $callable;
50
+	}
51 51
 
52
-    /**
53
-     * Alters the current item with $this->callable and returns a new item.
54
-     * Be careful with your types as we can't do static type checking here!
55
-     *
56
-     * @return mixed
57
-     */
58
-    public function current()
59
-    {
60
-        $callable = $this->callable;
52
+	/**
53
+	 * Alters the current item with $this->callable and returns a new item.
54
+	 * Be careful with your types as we can't do static type checking here!
55
+	 *
56
+	 * @return mixed
57
+	 */
58
+	public function current()
59
+	{
60
+		$callable = $this->callable;
61 61
 
62
-        return $callable($this->iterator->current());
63
-    }
62
+		return $callable($this->iterator->current());
63
+	}
64 64
 
65
-    public function next()
66
-    {
67
-        $this->iterator->next();
68
-    }
65
+	public function next()
66
+	{
67
+		$this->iterator->next();
68
+	}
69 69
 
70
-    public function key()
71
-    {
72
-        return $this->iterator->key();
73
-    }
70
+	public function key()
71
+	{
72
+		return $this->iterator->key();
73
+	}
74 74
 
75
-    public function valid()
76
-    {
77
-        return $this->iterator->valid();
78
-    }
75
+	public function valid()
76
+	{
77
+		return $this->iterator->valid();
78
+	}
79 79
 
80
-    public function rewind()
81
-    {
82
-        $this->iterator->rewind();
83
-    }
80
+	public function rewind()
81
+	{
82
+		$this->iterator->rewind();
83
+	}
84 84
 
85
-    /**
86
-     * Casts the iterator to a PHP array.
87
-     *
88
-     * @return array
89
-     */
90
-    public function toArray()
91
-    {
92
-        return iterator_to_array($this);
93
-    }
85
+	/**
86
+	 * Casts the iterator to a PHP array.
87
+	 *
88
+	 * @return array
89
+	 */
90
+	public function toArray()
91
+	{
92
+		return iterator_to_array($this);
93
+	}
94 94
 
95
-    public function jsonSerialize()
96
-    {
97
-        return $this->toArray();
98
-    }
95
+	public function jsonSerialize()
96
+	{
97
+		return $this->toArray();
98
+	}
99 99
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/ScalarBeanPropertyDescriptor.php 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -11,128 +11,128 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor
13 13
 {
14
-    /**
15
-     * @var Column
16
-     */
17
-    private $column;
18
-
19
-    public function __construct(Table $table, Column $column)
20
-    {
21
-        parent::__construct($table);
22
-        $this->table = $table;
23
-        $this->column = $column;
24
-    }
25
-
26
-    /**
27
-     * Returns the foreign-key the column is part of, if any. null otherwise.
28
-     *
29
-     * @return ForeignKeyConstraint|null
30
-     */
31
-    public function getForeignKey()
32
-    {
33
-        return false;
34
-    }
35
-
36
-    /**
37
-     * Returns the param annotation for this property (useful for constructor).
38
-     *
39
-     * @return string
40
-     */
41
-    public function getParamAnnotation()
42
-    {
43
-        $className = $this->getClassName();
44
-        $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType());
45
-
46
-        $str = '     * @param %s %s';
47
-
48
-        return sprintf($str, $paramType, $this->getVariableName());
49
-    }
50
-
51
-    public function getUpperCamelCaseName()
52
-    {
53
-        return TDBMDaoGenerator::toCamelCase($this->column->getName());
54
-    }
55
-
56
-    /**
57
-     * Returns the name of the class linked to this property or null if this is not a foreign key.
58
-     *
59
-     * @return null|string
60
-     */
61
-    public function getClassName()
62
-    {
63
-        return;
64
-    }
65
-
66
-    /**
67
-     * Returns true if the property is compulsory (and therefore should be fetched in the constructor).
68
-     *
69
-     * @return bool
70
-     */
71
-    public function isCompulsory()
72
-    {
73
-        return $this->column->getNotnull() && !$this->column->getAutoincrement() && $this->column->getDefault() === null;
74
-    }
75
-
76
-    /**
77
-     * Returns true if the property has a default value.
78
-     *
79
-     * @return bool
80
-     */
81
-    public function hasDefault()
82
-    {
83
-        return $this->column->getDefault() !== null;
84
-    }
85
-
86
-    /**
87
-     * Returns the code that assigns a value to its default value.
88
-     *
89
-     * @return string
90
-     */
91
-    public function assignToDefaultCode()
92
-    {
93
-        $str = '        $this->%s(%s);';
94
-
95
-        $default = $this->column->getDefault();
96
-
97
-        if (strtoupper($default) === 'CURRENT_TIMESTAMP') {
98
-            $defaultCode = 'new \DateTimeImmutable()';
99
-        } else {
100
-            $defaultCode = var_export($this->column->getDefault(), true);
101
-        }
102
-
103
-        return sprintf($str, $this->getSetterName(), $defaultCode);
104
-    }
105
-
106
-    /**
107
-     * Returns true if the property is the primary key.
108
-     *
109
-     * @return bool
110
-     */
111
-    public function isPrimaryKey()
112
-    {
113
-        return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns());
114
-    }
115
-
116
-    /**
117
-     * Returns the PHP code for getters and setters.
118
-     *
119
-     * @return string
120
-     */
121
-    public function getGetterSetterCode()
122
-    {
123
-        $type = $this->column->getType();
124
-        $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
125
-
126
-        $columnGetterName = $this->getGetterName();
127
-        $columnSetterName = $this->getSetterName();
128
-
129
-        if ($normalizedType == '\\DateTimeInterface') {
130
-            $castTo = '\\DateTimeInterface ';
131
-        } else {
132
-            $castTo = '';
133
-        }
134
-
135
-        $getterAndSetterCode = '    /**
14
+	/**
15
+	 * @var Column
16
+	 */
17
+	private $column;
18
+
19
+	public function __construct(Table $table, Column $column)
20
+	{
21
+		parent::__construct($table);
22
+		$this->table = $table;
23
+		$this->column = $column;
24
+	}
25
+
26
+	/**
27
+	 * Returns the foreign-key the column is part of, if any. null otherwise.
28
+	 *
29
+	 * @return ForeignKeyConstraint|null
30
+	 */
31
+	public function getForeignKey()
32
+	{
33
+		return false;
34
+	}
35
+
36
+	/**
37
+	 * Returns the param annotation for this property (useful for constructor).
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function getParamAnnotation()
42
+	{
43
+		$className = $this->getClassName();
44
+		$paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType());
45
+
46
+		$str = '     * @param %s %s';
47
+
48
+		return sprintf($str, $paramType, $this->getVariableName());
49
+	}
50
+
51
+	public function getUpperCamelCaseName()
52
+	{
53
+		return TDBMDaoGenerator::toCamelCase($this->column->getName());
54
+	}
55
+
56
+	/**
57
+	 * Returns the name of the class linked to this property or null if this is not a foreign key.
58
+	 *
59
+	 * @return null|string
60
+	 */
61
+	public function getClassName()
62
+	{
63
+		return;
64
+	}
65
+
66
+	/**
67
+	 * Returns true if the property is compulsory (and therefore should be fetched in the constructor).
68
+	 *
69
+	 * @return bool
70
+	 */
71
+	public function isCompulsory()
72
+	{
73
+		return $this->column->getNotnull() && !$this->column->getAutoincrement() && $this->column->getDefault() === null;
74
+	}
75
+
76
+	/**
77
+	 * Returns true if the property has a default value.
78
+	 *
79
+	 * @return bool
80
+	 */
81
+	public function hasDefault()
82
+	{
83
+		return $this->column->getDefault() !== null;
84
+	}
85
+
86
+	/**
87
+	 * Returns the code that assigns a value to its default value.
88
+	 *
89
+	 * @return string
90
+	 */
91
+	public function assignToDefaultCode()
92
+	{
93
+		$str = '        $this->%s(%s);';
94
+
95
+		$default = $this->column->getDefault();
96
+
97
+		if (strtoupper($default) === 'CURRENT_TIMESTAMP') {
98
+			$defaultCode = 'new \DateTimeImmutable()';
99
+		} else {
100
+			$defaultCode = var_export($this->column->getDefault(), true);
101
+		}
102
+
103
+		return sprintf($str, $this->getSetterName(), $defaultCode);
104
+	}
105
+
106
+	/**
107
+	 * Returns true if the property is the primary key.
108
+	 *
109
+	 * @return bool
110
+	 */
111
+	public function isPrimaryKey()
112
+	{
113
+		return in_array($this->column->getName(), $this->table->getPrimaryKeyColumns());
114
+	}
115
+
116
+	/**
117
+	 * Returns the PHP code for getters and setters.
118
+	 *
119
+	 * @return string
120
+	 */
121
+	public function getGetterSetterCode()
122
+	{
123
+		$type = $this->column->getType();
124
+		$normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
125
+
126
+		$columnGetterName = $this->getGetterName();
127
+		$columnSetterName = $this->getSetterName();
128
+
129
+		if ($normalizedType == '\\DateTimeInterface') {
130
+			$castTo = '\\DateTimeInterface ';
131
+		} else {
132
+			$castTo = '';
133
+		}
134
+
135
+		$getterAndSetterCode = '    /**
136 136
      * The getter for the "%s" column.
137 137
      *
138 138
      * @return %s
@@ -152,50 +152,50 @@  discard block
 block discarded – undo
152 152
 
153 153
 ';
154 154
 
155
-        return sprintf($getterAndSetterCode,
156
-            // Getter
157
-            $this->column->getName(),
158
-            $normalizedType,
159
-            $columnGetterName,
160
-            var_export($this->column->getName(), true),
161
-            var_export($this->table->getName(), true),
162
-            // Setter
163
-            $this->column->getName(),
164
-            $normalizedType,
165
-            $this->column->getName(),
166
-            $columnSetterName,
167
-            $castTo,
168
-            $this->column->getName().($castTo ? ($this->column->getNotnull() ? '' : ' = null') : ''),
169
-            var_export($this->column->getName(), true),
170
-            $this->column->getName(),
171
-            var_export($this->table->getName(), true)
172
-        );
173
-    }
174
-
175
-    /**
176
-     * Returns the part of code useful when doing json serialization.
177
-     *
178
-     * @return string
179
-     */
180
-    public function getJsonSerializeCode()
181
-    {
182
-        $type = $this->column->getType();
183
-        $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
184
-
185
-        if ($normalizedType == '\\DateTimeInterface') {
186
-            return '        $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null)?null:$this->'.$this->getGetterName()."()->format('c');\n";
187
-        } else {
188
-            return '        $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n";
189
-        }
190
-    }
191
-
192
-    /**
193
-     * Returns the column name.
194
-     *
195
-     * @return string
196
-     */
197
-    public function getColumnName()
198
-    {
199
-        return $this->column->getName();
200
-    }
155
+		return sprintf($getterAndSetterCode,
156
+			// Getter
157
+			$this->column->getName(),
158
+			$normalizedType,
159
+			$columnGetterName,
160
+			var_export($this->column->getName(), true),
161
+			var_export($this->table->getName(), true),
162
+			// Setter
163
+			$this->column->getName(),
164
+			$normalizedType,
165
+			$this->column->getName(),
166
+			$columnSetterName,
167
+			$castTo,
168
+			$this->column->getName().($castTo ? ($this->column->getNotnull() ? '' : ' = null') : ''),
169
+			var_export($this->column->getName(), true),
170
+			$this->column->getName(),
171
+			var_export($this->table->getName(), true)
172
+		);
173
+	}
174
+
175
+	/**
176
+	 * Returns the part of code useful when doing json serialization.
177
+	 *
178
+	 * @return string
179
+	 */
180
+	public function getJsonSerializeCode()
181
+	{
182
+		$type = $this->column->getType();
183
+		$normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type);
184
+
185
+		if ($normalizedType == '\\DateTimeInterface') {
186
+			return '        $array['.var_export($this->getLowerCamelCaseName(), true).'] = ($this->'.$this->getGetterName().'() === null)?null:$this->'.$this->getGetterName()."()->format('c');\n";
187
+		} else {
188
+			return '        $array['.var_export($this->getLowerCamelCaseName(), true).'] = $this->'.$this->getGetterName()."();\n";
189
+		}
190
+	}
191
+
192
+	/**
193
+	 * Returns the column name.
194
+	 *
195
+	 * @return string
196
+	 */
197
+	public function getColumnName()
198
+	{
199
+		return $this->column->getName();
200
+	}
201 201
 }
Please login to merge, or discard this patch.