PackageGenerator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
generatePackage() 0 1 ?
getIdentifier() 0 1 ?
A getCache() 0 3 1
A setCache() 0 3 1
A getPackageFilename() 0 14 3
1
<?php
2
3
/**
4
 * Represents a back-end for generating a package file.
5
 * A package file is a .tar.gz file of the project, ready to be uploaded to the server
6
 *
7
 * These package generators can be used by applicable deployment backends.
8
 */
9
abstract class PackageGenerator {
10
11
	protected $cache;
12
13
	/**
14
	 * Generate the package file, saving to the given location
15
	 *
16
	 * @param string $baseDir string The base directory of the project, checked out from git.
17
	 * @param $outputFilename string The filename to write to.
18
	 * @param string $sha
19
	 *
20
	 * @return boolean True on success
21
	 */
22
	abstract public function generatePackage($sha, $baseDir, $outputFilename, \DeploynautLogFile $log);
23
24
	/**
25
	 * Return a string that uniquely identifies this package generator.
26
	 *
27
	 * This will be used as part of cache keys; if meaningful changes to the operation of the generator are
28
	 * made, then the identifier should change. Note there is no need to include the classname in the
29
	 * identifier; callers to getIdentifier() should be responsible for disambiguating based on class.
30
	 */
31
	abstract public function getIdentifier();
32
33
	public function getCache() {
34
		return $this->cache;
35
	}
36
37
	public function setCache(PackageCache $cache) {
38
		$this->cache = $cache;
39
	}
40
41
	/**
42
	 * Generate or retrieve a package from the cache
43
	 *
44
	 * @param string $identifier A unique identifier for the generator; used to partition the cache
45
	 * @param string $sha The SHA of the commit to be deployed
46
	 * @param string $repositoryDir The directory where the repository resides
47
	 * @param \DeploynautLogFile $log The log to write status output to, including package-generation commands
48
	 *
49
	 * @return string
50
	 */
51
	public function getPackageFilename($identifier, $sha, $repositoryDir, \DeploynautLogFile $log) {
52
		// Fetch through the cache
53
		if($this->cache) {
54
			$identifier .= '-' . get_class($this) . '-' . $this->getIdentifier();
55
 			return $this->cache->getPackageFilename($this, $identifier, $sha, $repositoryDir, $log);
56
57
 		// Default, cacheless implementation
58
 		} else {
59
 			$filename = TEMP_FOLDER . '/' . $sha . '.tar.gz';
60
 			if($this->generatePackage($sha, $repositoryDir, $filename, $log)) {
61
 				return $filename;
62
 			}
63
 		}
64
	}
65
66
}
67