Completed
Push — test ( baa35b...e4e76c )
by Temitope
02:58
created
src/Model/BaseModel.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -8,164 +8,164 @@  discard block
 block discarded – undo
8 8
 
9 9
 class BaseModel implements BaseModelInterface
10 10
 {
11
-    // Inject the inflector trait
12
-    use Inflector;
13
-
14
-    // Private variable that contains instance of database
15
-    protected $databaseModel;
16
-
17
-    // Class variable holding class name pluralized
18
-    protected $tableName;
19
-
20
-    // Properties will later contain key, value pairs from the magic setter, getter methods
21
-    protected $properties = [];
22
-
23
-    public function __construct()
24
-    {
25
-        $this->tableName = $this->getClassName();
26
-
27
-        $this->databaseModel = new DatabaseHandler($this->tableName);
28
-
29
-        $this->properties['id'] = 0;
30
-    }
31
-
32
-    /**
33
-     * The magic getter method.
34
-     *
35
-     * @params key
36
-     *
37
-     * @return array key
38
-     */
39
-    public function __get($key)
40
-    {
41
-        $this->properties[$key];
42
-    }
43
-
44
-    /**
45
-     * The magic setter method.
46
-     *
47
-     * @params property, key
48
-     *
49
-     * @return array associative array properties
50
-     */
51
-    public function __set($property, $value)
52
-    {
53
-        $this->properties[$property] = $value;
54
-    }
55
-
56
-    /**
57
-     * This method gets all the record from a particular table.
58
-     *
59
-     * @params void
60
-     *
61
-     * @throws NoRecordFoundException
62
-     *
63
-     * @return associative array
64
-     */
65
-    public static function getAll()
66
-    {
67
-        $allData = DatabaseHandler::read($id = false, self::getClassName());
68
-
69
-        if (count($allData) > 0) {
70
-            return $allData;
71
-        }
72
-
73
-        throw NoRecordFoundException::create('There is no record to display');
74
-    }
75
-
76
-    /**
77
-     * This method create or update record in a database table.
78
-     *
79
-     * @params void
80
-     *
81
-     * @throws EmptyArrayException
82
-     * @throws NoRecordInsertionException
83
-     * @throws NoRecordUpdateException
84
-     *
85
-     * @return bool true or false;
86
-     */
87
-    public function save()
88
-    {
89
-        $boolCommit = false;
90
-
91
-        if ($this->properties['id']) {
92
-            $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName());
93
-
94
-            if ($this->checkIfRecordIsEmpty($allData)) {
95
-                $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties);
96
-
97
-                if ($boolCommit) {
98
-                    return true;
99
-                }
100
-
101
-                throw NoRecordUpdateException::create('Record not updated successfully');
102
-            }
103
-
104
-            throw EmptyArrayException::create("Value passed didn't match any record");
105
-        }
106
-
107
-        $boolCommit = $this->databaseModel->create($this->properties, $this->tableName);
108
-
109
-        if ($boolCommit) {
110
-            return true;
111
-        }
112
-
113
-        throw NoRecordInsertionException::create('Record not created successfully');
114
-    }
115
-
116
-    /**
117
-     * This method find a record by id.
118
-     *
119
-     * @params int id
120
-     *
121
-     * @throws NoArgumentPassedToFunctionException
122
-     *
123
-     * @return object
124
-     */
125
-    public static function find($id)
126
-    {
127
-        $num_args = (int) func_num_args(); // get number of arguments passed to this function
128
-        if ($num_args == 0 || $num_args > 1) {
129
-            throw NoArgumentPassedToFunctionException::create('Argument missing: only one argument is allowed');
130
-        }
131
-
132
-        if ($id == '') {
133
-            throw NullArgumentPassedToFunction::create('This function expect a value');
134
-        }
135
-
136
-        $staticFindInstance = new static();
137
-        $staticFindInstance->id = $id == '' ? false : $id;
138
-
139
-        return $staticFindInstance;
140
-    }
141
-
142
-    /**
143
-     * This method delete a row from the table by the row id.
144
-     *
145
-     * @params int id
146
-     *
147
-     * @throws NoRecordDeletionException;
148
-     *
149
-     * @return bool true or false
150
-     */
151
-    public static function destroy($id)
152
-    {
153
-        $boolDeleted = false;
154
-
155
-        $num_args = (int) func_num_args(); // get number of arguments passed to this function
156
-
157
-        if ($num_args == 0 || $num_args > 1) {
158
-            throw NoArgumentPassedToFunctionException::create('Argument missing: only one argument is allowed');
159
-        }
160
-
161
-        $boolDeleted = DatabaseHandler::delete($id, self::getClassName());
162
-
163
-        if ($boolDeleted) {
164
-            return true;
165
-        }
166
-
167
-        throw NoRecordDeletionException::create('Record deletion unsuccessful because id does not match any record');
168
-    }
11
+	// Inject the inflector trait
12
+	use Inflector;
13
+
14
+	// Private variable that contains instance of database
15
+	protected $databaseModel;
16
+
17
+	// Class variable holding class name pluralized
18
+	protected $tableName;
19
+
20
+	// Properties will later contain key, value pairs from the magic setter, getter methods
21
+	protected $properties = [];
22
+
23
+	public function __construct()
24
+	{
25
+		$this->tableName = $this->getClassName();
26
+
27
+		$this->databaseModel = new DatabaseHandler($this->tableName);
28
+
29
+		$this->properties['id'] = 0;
30
+	}
31
+
32
+	/**
33
+	 * The magic getter method.
34
+	 *
35
+	 * @params key
36
+	 *
37
+	 * @return array key
38
+	 */
39
+	public function __get($key)
40
+	{
41
+		$this->properties[$key];
42
+	}
43
+
44
+	/**
45
+	 * The magic setter method.
46
+	 *
47
+	 * @params property, key
48
+	 *
49
+	 * @return array associative array properties
50
+	 */
51
+	public function __set($property, $value)
52
+	{
53
+		$this->properties[$property] = $value;
54
+	}
55
+
56
+	/**
57
+	 * This method gets all the record from a particular table.
58
+	 *
59
+	 * @params void
60
+	 *
61
+	 * @throws NoRecordFoundException
62
+	 *
63
+	 * @return associative array
64
+	 */
65
+	public static function getAll()
66
+	{
67
+		$allData = DatabaseHandler::read($id = false, self::getClassName());
68
+
69
+		if (count($allData) > 0) {
70
+			return $allData;
71
+		}
72
+
73
+		throw NoRecordFoundException::create('There is no record to display');
74
+	}
75
+
76
+	/**
77
+	 * This method create or update record in a database table.
78
+	 *
79
+	 * @params void
80
+	 *
81
+	 * @throws EmptyArrayException
82
+	 * @throws NoRecordInsertionException
83
+	 * @throws NoRecordUpdateException
84
+	 *
85
+	 * @return bool true or false;
86
+	 */
87
+	public function save()
88
+	{
89
+		$boolCommit = false;
90
+
91
+		if ($this->properties['id']) {
92
+			$allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName());
93
+
94
+			if ($this->checkIfRecordIsEmpty($allData)) {
95
+				$boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties);
96
+
97
+				if ($boolCommit) {
98
+					return true;
99
+				}
100
+
101
+				throw NoRecordUpdateException::create('Record not updated successfully');
102
+			}
103
+
104
+			throw EmptyArrayException::create("Value passed didn't match any record");
105
+		}
106
+
107
+		$boolCommit = $this->databaseModel->create($this->properties, $this->tableName);
108
+
109
+		if ($boolCommit) {
110
+			return true;
111
+		}
112
+
113
+		throw NoRecordInsertionException::create('Record not created successfully');
114
+	}
115
+
116
+	/**
117
+	 * This method find a record by id.
118
+	 *
119
+	 * @params int id
120
+	 *
121
+	 * @throws NoArgumentPassedToFunctionException
122
+	 *
123
+	 * @return object
124
+	 */
125
+	public static function find($id)
126
+	{
127
+		$num_args = (int) func_num_args(); // get number of arguments passed to this function
128
+		if ($num_args == 0 || $num_args > 1) {
129
+			throw NoArgumentPassedToFunctionException::create('Argument missing: only one argument is allowed');
130
+		}
131
+
132
+		if ($id == '') {
133
+			throw NullArgumentPassedToFunction::create('This function expect a value');
134
+		}
135
+
136
+		$staticFindInstance = new static();
137
+		$staticFindInstance->id = $id == '' ? false : $id;
138
+
139
+		return $staticFindInstance;
140
+	}
141
+
142
+	/**
143
+	 * This method delete a row from the table by the row id.
144
+	 *
145
+	 * @params int id
146
+	 *
147
+	 * @throws NoRecordDeletionException;
148
+	 *
149
+	 * @return bool true or false
150
+	 */
151
+	public static function destroy($id)
152
+	{
153
+		$boolDeleted = false;
154
+
155
+		$num_args = (int) func_num_args(); // get number of arguments passed to this function
156
+
157
+		if ($num_args == 0 || $num_args > 1) {
158
+			throw NoArgumentPassedToFunctionException::create('Argument missing: only one argument is allowed');
159
+		}
160
+
161
+		$boolDeleted = DatabaseHandler::delete($id, self::getClassName());
162
+
163
+		if ($boolDeleted) {
164
+			return true;
165
+		}
166
+
167
+		throw NoRecordDeletionException::create('Record deletion unsuccessful because id does not match any record');
168
+	}
169 169
 
170 170
    /**
171 171
     * This method return the current class name
@@ -175,26 +175,26 @@  discard block
 block discarded – undo
175 175
     */
176 176
    public static function getClassName()
177 177
    {
178
-       $tableName = preg_split('/(?=[A-Z])/', get_called_class());
178
+	   $tableName = preg_split('/(?=[A-Z])/', get_called_class());
179 179
 
180
-       $className = end($tableName);
180
+	   $className = end($tableName);
181 181
 
182
-       return self::pluralize(strtolower($className));
182
+	   return self::pluralize(strtolower($className));
183 183
    }
184 184
 
185
-    /**
186
-     * This method check if the argument passed to this function is an array.
187
-     *
188
-     * @param $arrayOfRecord
189
-     *
190
-     * @return bool
191
-     */
192
-    public function checkIfRecordIsEmpty($arrayOfRecord)
193
-    {
194
-        if (count($arrayOfRecord) > 0) {
195
-            return true;
196
-        }
197
-
198
-        return false;
199
-    }
185
+	/**
186
+	 * This method check if the argument passed to this function is an array.
187
+	 *
188
+	 * @param $arrayOfRecord
189
+	 *
190
+	 * @return bool
191
+	 */
192
+	public function checkIfRecordIsEmpty($arrayOfRecord)
193
+	{
194
+		if (count($arrayOfRecord) > 0) {
195
+			return true;
196
+		}
197
+
198
+		return false;
199
+	}
200 200
 }
Please login to merge, or discard this patch.
src/Helper/Inflector.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -37,62 +37,62 @@
 block discarded – undo
37 37
 
38 38
 trait Inflector
39 39
 {
40
-    /**
41
-     * Pluralizes English nouns.
42
-     *
43
-     * @static
44
-     *
45
-     * @param string $word English noun to pluralize
46
-     *
47
-     * @return string Plural noun
48
-     */
49
-    public static function pluralize($word)
50
-    {
51
-        $plural = [
52
-            '/(quiz)$/i'                     => '$1zes',
53
-            '/^(ox)$/i'                      => '$1en',
54
-            '/([m|l])ouse$/i'                => '$1ice',
55
-            '/(matr|vert|ind)ix|ex$/i'       => '$1ices',
56
-            '/(x|ch|ss|sh)$/i'               => '$1es',
57
-            '/([^aeiouy]|qu)y$/i'            => '$1ies',
58
-            '/(hive)$/i'                     => '$1s',
59
-            '/(?:([^f])fe|([lr])f)$/i'       => '$1$2ves',
60
-            '/(shea|lea|loa|thie)f$/i'       => '$1ves',
61
-            '/sis$/i'                        => 'ses',
62
-            '/([ti])um$/i'                   => '$1a',
63
-            '/(tomat|potat|ech|her|vet)o$/i' => '$1oes',
64
-            '/(bu)s$/i'                      => '$1ses',
65
-            '/(alias)$/i'                    => '$1es',
66
-            '/(octop)us$/i'                  => '$1i',
67
-            '/(ax|test)is$/i'                => '$1es',
68
-            '/(us)$/i'                       => '$1es',
69
-            '/s$/i'                          => 's',
70
-            '/$/'                            => 's',
71
-        ];
72
-        $uncountable = ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'];
73
-        $irregular = [
74
-            'person' => 'people',
75
-            'man'    => 'men',
76
-            'child'  => 'children',
77
-            'sex'    => 'sexes',
78
-            'move'   => 'moves', ];
79
-        $lowercased_word = strtolower($word);
80
-        foreach ($uncountable as $_uncountable) {
81
-            if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
82
-                return $word;
83
-            }
84
-        }
85
-        foreach ($irregular as $_plural => $_singular) {
86
-            if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
87
-                return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
88
-            }
89
-        }
90
-        foreach ($plural as $rule => $replacement) {
91
-            if (preg_match($rule, $word)) {
92
-                return preg_replace($rule, $replacement, $word);
93
-            }
94
-        }
40
+	/**
41
+	 * Pluralizes English nouns.
42
+	 *
43
+	 * @static
44
+	 *
45
+	 * @param string $word English noun to pluralize
46
+	 *
47
+	 * @return string Plural noun
48
+	 */
49
+	public static function pluralize($word)
50
+	{
51
+		$plural = [
52
+			'/(quiz)$/i'                     => '$1zes',
53
+			'/^(ox)$/i'                      => '$1en',
54
+			'/([m|l])ouse$/i'                => '$1ice',
55
+			'/(matr|vert|ind)ix|ex$/i'       => '$1ices',
56
+			'/(x|ch|ss|sh)$/i'               => '$1es',
57
+			'/([^aeiouy]|qu)y$/i'            => '$1ies',
58
+			'/(hive)$/i'                     => '$1s',
59
+			'/(?:([^f])fe|([lr])f)$/i'       => '$1$2ves',
60
+			'/(shea|lea|loa|thie)f$/i'       => '$1ves',
61
+			'/sis$/i'                        => 'ses',
62
+			'/([ti])um$/i'                   => '$1a',
63
+			'/(tomat|potat|ech|her|vet)o$/i' => '$1oes',
64
+			'/(bu)s$/i'                      => '$1ses',
65
+			'/(alias)$/i'                    => '$1es',
66
+			'/(octop)us$/i'                  => '$1i',
67
+			'/(ax|test)is$/i'                => '$1es',
68
+			'/(us)$/i'                       => '$1es',
69
+			'/s$/i'                          => 's',
70
+			'/$/'                            => 's',
71
+		];
72
+		$uncountable = ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'];
73
+		$irregular = [
74
+			'person' => 'people',
75
+			'man'    => 'men',
76
+			'child'  => 'children',
77
+			'sex'    => 'sexes',
78
+			'move'   => 'moves', ];
79
+		$lowercased_word = strtolower($word);
80
+		foreach ($uncountable as $_uncountable) {
81
+			if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
82
+				return $word;
83
+			}
84
+		}
85
+		foreach ($irregular as $_plural => $_singular) {
86
+			if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
87
+				return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
88
+			}
89
+		}
90
+		foreach ($plural as $rule => $replacement) {
91
+			if (preg_match($rule, $word)) {
92
+				return preg_replace($rule, $replacement, $word);
93
+			}
94
+		}
95 95
 
96
-        return false;
97
-    }
96
+		return false;
97
+	}
98 98
 }
Please login to merge, or discard this patch.
src/Exceptions/NoRecordFoundException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class NoRecordDeletionException extends Exception
12 12
 {
13
-    public static function create($message)
14
-    {
15
-        return new static($message);
16
-    }
13
+	public static function create($message)
14
+	{
15
+		return new static($message);
16
+	}
17 17
 }
Please login to merge, or discard this patch.
src/Exceptions/TableNotCreatedException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class NoRecordDeletionException extends Exception
12 12
 {
13
-    public static function create($message)
14
-    {
15
-        return new static($message);
16
-    }
13
+	public static function create($message)
14
+	{
15
+		return new static($message);
16
+	}
17 17
 }
Please login to merge, or discard this patch.
src/Exceptions/NoArgumentPassedToFunctionException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class NoRecordDeletionException extends Exception
12 12
 {
13
-    public static function create($message)
14
-    {
15
-        return new static($message);
16
-    }
13
+	public static function create($message)
14
+	{
15
+		return new static($message);
16
+	}
17 17
 }
Please login to merge, or discard this patch.
src/Exceptions/EmptyArrayException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class NoRecordDeletionException extends Exception
12 12
 {
13
-    public static function create($message)
14
-    {
15
-        return new static($message);
16
-    }
13
+	public static function create($message)
14
+	{
15
+		return new static($message);
16
+	}
17 17
 }
Please login to merge, or discard this patch.
src/Exceptions/NoRecordUpdateException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 
11 11
 class NoRecordDeletionException extends Exception
12 12
 {
13
-    public static function create($message)
14
-    {
15
-        return new static($message);
16
-    }
13
+	public static function create($message)
14
+	{
15
+		return new static($message);
16
+	}
17 17
 }
Please login to merge, or discard this patch.