BaseModel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrateObjects() 0 19 4
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
}