ShellModelTruncator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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
}