CompressedBinary   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
getOutputFileName() 0 1 ?
getExtractedName() 0 1 ?
A save() 0 21 4
A exists() 0 4 1
1
<?php
2
namespace Peridot\WebDriverManager\Binary;
3
4
/**
5
 * CompressedBinary extends the AbstractBinary to include behavior
6
 * for handling compressed binaries.
7
 *
8
 * @package Peridot\WebDriverManager\Binary
9
 */
10
abstract class CompressedBinary extends AbstractBinary
11
{
12
    /**
13
     * Overrides default save behavior to first decompress
14
     * an archive format before saving it to a directory.
15
     *
16
     * @param string $directory
17
     * @return bool
18
     */
19
    public function save($directory)
20
    {
21
        if (empty($this->contents)) {
22
            return false;
23
        }
24
25
        if ($this->exists($directory)) {
26
            return true;
27
        }
28
29
        $compressedPath = $directory . DIRECTORY_SEPARATOR . $this->getOutputFileName();
30
        $this->removeOldVersions($directory);
31
        file_put_contents($compressedPath, $this->contents);
32
        $extracted = $this->resolver->extract($compressedPath, $directory);
33
34
        if ($extracted) {
35
            chmod("$directory/{$this->getExtractedName()}", 0777);
36
        }
37
38
        return $extracted;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @param $directory
45
     * @return bool
46
     */
47
    public function exists($directory)
48
    {
49
        return file_exists("$directory/{$this->getOutputFileName()}");
50
    }
51
52
    /**
53
     * Return the output filename for the compressed binary.
54
     *
55
     * @return string
56
     */
57
    abstract public function getOutputFileName();
58
59
    /**
60
     * Get the name of the extracted binary.
61
     *
62
     * @return string
63
     */
64
    abstract public function getExtractedName();
65
}
66