Completed
Pull Request — master (#672)
by Sean
10:23 queued 03:39
created

CreateEnvJob   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B perform() 0 22 4
A updateStatus() 0 8 1
A DNData() 0 3 1
1
<?php
2
class CreateEnvJob extends DeploynautJob {
3
4
	/**
5
	 *
6
	 * @var array
7
	 */
8
	public $args;
9
10
	/**
11
	 *
12
	 */
13
	public function setUp() {
14
		$this->updateStatus('Started');
15
		chdir(BASE_PATH);
16
	}
17
18
	/**
19
	 *
20
	 */
21
	public function perform() {
22
		echo "[-] CreateEnvJob starting" . PHP_EOL;
23
		$log = new DeploynautLogFile($this->args['logfile']);
24
		$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
25
26
		try {
27
			if(!($envCreate && $envCreate->exists())) {
28
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
29
			}
30
31
			// This will throw and exception if it fails.
32
			$envCreate->createEnvironment();
33
34
		} catch(Exception $e) {
35
			$log->write($e->getMessage());
36
			echo "[-] CreateEnvJob failed" . PHP_EOL;
37
			throw $e;
38
		}
39
40
		$this->updateStatus('Finished');
41
		echo "[-] CreateEnvJob finished" . PHP_EOL;
42
	}
43
44
	/**
45
	 *
46
	 * @param string $status
47
	 * @global array $databaseConfig
48
	 */
49
	protected function updateStatus($status) {
50
		global $databaseConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
51
		DB::connect($databaseConfig);
52
53
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
54
		$record->Status = $status;
55
		$record->write();
56
	}
57
58
	/**
59
	 *
60
	 * @return DNData
61
	 */
62
	protected function DNData() {
63
		return DNData::inst();
64
	}
65
}
66
67