BaseModel::hydrateObjects()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 19
rs 9.2
cc 4
eloc 10
nc 4
nop 3
1
<?php
2
namespace Kineo\Model;
3
	
4
interface ModelInterface
5
{
6
	function hydrateObjects($collectionPropertyName, $modelType, $records);
7
}
8
9
class BaseModel implements ModelInterface
0 ignored issues
show
Coding Style Compatibility introduced by
Each interface must be in a file by itself

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
10
{
11
	public function hydrateObjects($collectionPropertyName, $modelType, $records)
12
	{
13
		if(empty($records)) {
14
			throw new \Exception('No records found');
15
		} else {
16
			foreach($records as $item) {
17
				// Requires a fully qualified namespace
18
				$doc = new $modelType($this->app);
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
				
20
				foreach($item as $key => $val) {
21
					$doc->{$key} = $val;
22
				}
23
				
24
				$this->{$collectionPropertyName}[] = $doc;
25
			}
26
			
27
			return $this->{$collectionPropertyName};
28
		}
29
	}
30
}