ShellModelTruncator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 34
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A truncateModels() 0 8 2
1
<?php
2
3
/**
4
 * Shell Model Truncator
5
 */
6
class ShellModelTruncator {
7
8
	/**
9
	 * The shell or shel task object for interacting with the console
10
	 *
11
	 * @var null|Shell
12
	 */
13
	protected $_shell = null;
14
15
	/**
16
	 * ModelTruncator constructor
17
	 *
18
	 * @param Shell $shell A shell or shell task object.
19
	 */
20
	public function __construct($shell) {
21
		$this->_shell = $shell;
22
	}
23
24
	/**
25
	 * Truncate the given models
26
	 *
27
	 * @param array $modelsToTruncate An array of models (names) to truncate
28
	 * @return void
29
	 * @todo Improve testability by extracting the model object retrieval part.
30
	 */
31
	public function truncateModels($modelsToTruncate) {
32
		foreach ($modelsToTruncate as $modelName) {
33
			$this->_shell->out(__('Truncate model %s...', $modelName), 1, Shell::VERBOSE);
34
			$model = ClassRegistry::init($modelName);
35
			$datasource = $model->getDataSource();
36
			$datasource->truncate($model->tablePrefix . $model->useTable);
37
		}
38
	}
39
}