Passed
Push — master ( b2cb2f...f11c06 )
by Sébastien
04:43
created

JvmFileUtils   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 35
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isDirectoryWritable() 0 17 4
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\Jasper\Io;
6
7
use Soluble\Japha\Bridge\Adapter as BridgeAdapter;
8
9
class JvmFileUtils
10
{
11
    /**
12
     * @var BridgeAdapter
13
     */
14
    protected $ba;
15
16
    public function __construct(BridgeAdapter $ba)
17
    {
18
        $this->ba = $ba;
19
    }
20
21
    /**
22
     * @param string $directory
23
     *
24
     * @throws \Soluble\Japha\Bridge\Exception\ClassNotFoundException
25
     * @throws \Soluble\Japha\Bridge\Exception\JavaException
26
     */
27
    public function isDirectoryWritable(string $directory): bool
28
    {
29
        try {
30
            $jFile = $this->ba->java('java.io.File', $directory);
31
        } catch (JavaException $e) {
0 ignored issues
show
Bug introduced by
The type Soluble\Jasper\Io\JavaException was not found. Did you mean JavaException? If so, make sure to prefix the type with \.
Loading history...
32
            throw $e;
33
        }
34
35
        if (!$jFile->exists()) {
36
            throw new Exception\InvalidDirectoryException(sprintf('Directory \'%s\' does not exists (jvm-side)', $directory));
37
        }
38
39
        if (!$jFile->isDirectory()) {
40
            throw new Exception\InvalidDirectoryException(sprintf('Path \'%s\' is not a directory (jvm-side)', $directory));
41
        }
42
43
        return $jFile->canWrite();
44
    }
45
}
46