Completed
Push — master ( 499e80...f97bb0 )
by Jean-Christophe
01:49
created

TableExport::scanManyToManys()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
3
namespace Ubiquity\db\export;
4
5
use Ubiquity\orm\OrmUtils;
6
use Ubiquity\orm\DAO;
7
8
class TableExport extends DataExport{
9
	protected $model;
10
	protected $metas;
11
	public function __construct($model,$batchSize=20){
12
		parent::__construct($batchSize);
13
		$this->model=$model;
14
		$this->batchSize=$batchSize;
15
	}
16
17
	public function exports(DbExport $dbExport,$condition=""){
18
		$table=OrmUtils::getTableName($this->model);
19
		$this->metas=OrmUtils::getModelMetadata($this->model);
20
		$manyToManys=[];
21
		if(isset($this->metas["#manyToMany"]))
22
			$manyToManys=$this->metas["#manyToMany"];
23
		$this->scanManyToManys($dbExport, $manyToManys);
24
		$fields=\array_diff($this->metas["#fieldNames"],$this->metas["#notSerializable"]);
25
		$datas=DAO::getAll($this->model,$condition);
26
		return $this->generateInsert($table, $fields, $datas);
27
	}
28
29 View Code Duplication
	protected function scanManyToManys(DbExport $dbExport,$manyToManys){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
		foreach ($manyToManys as $member=>$manyToMany){
31
			if(isset($this->metas["#joinTable"][$member])){
32
				$annotJoinTable=$this->metas["#joinTable"][$member];
33
				$dbExport->addManyToMany($annotJoinTable["name"], ["member"=>$member,"class"=>$this->model]);
34
			}
35
		}
36
	}
37
}
38