UpdateCloudAssetsTask   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 3
1
<?php
2
/**
3
 * Simply calls updateCloudStatus on every file in the db.
4
 * Allows you to get a new server or development environment synced up easily.
5
 *
6
 * @author Mark Guinn <[email protected]>
7
 * @date 01.14.2014
8
 * @package cloudassets
9
 * @subpackage tasks
10
 */
11
class UpdateCloudAssetsTask extends BuildTask
12
{
13
	protected $title = 'Cloud Assets: Update All Files';
14
	protected $description = 'Simply calls updateCloudStatus on every file in the db. Allows you to get a new server or development environment synced up easily.';
15
16
17
	public function run($request) {
18
		$buckets = Config::inst()->get('CloudAssets', 'map');
19
20
		foreach ($buckets as $basePath => $cfg) {
0 ignored issues
show
Bug introduced by
The expression $buckets of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
21
			echo "processing $basePath...\n";
22
			$files = File::get()->filter('Filename:StartsWith', ltrim($basePath, '/'));
23
			foreach ($files as $f) {
24
				echo " - {$f->Filename}: {$f->CloudStatus} - placeholder={$f->containsPlaceholder()}\n";
25
				$f->updateCloudStatus();
26
				$f->createLocalIfNeeded();
27
			}
28
		}
29
30
		echo "done\n\n";
31
	}
32
33
}