JvmFileUtils::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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
use Soluble\Japha\Bridge\Exception\JavaException;
9
10
class JvmFileUtils
11
{
12
    /**
13
     * @var BridgeAdapter
14
     */
15
    protected $ba;
16
17 9
    public function __construct(BridgeAdapter $ba)
18
    {
19 9
        $this->ba = $ba;
20 9
    }
21
22
    /**
23
     * @throws \Soluble\Japha\Bridge\Exception\ClassNotFoundException
24
     * @throws \Soluble\Japha\Bridge\Exception\JavaException
25
     * @throws Exception\InvalidDirectoryException
26
     */
27 9
    public function isDirectoryWritable(string $directory): bool
28
    {
29
        try {
30 9
            $jFile = $this->ba->java('java.io.File', $directory);
31
        } catch (JavaException $e) {
32
            throw $e;
33
        }
34
35 9
        if (!$jFile->exists()) {
36
            throw new Exception\InvalidDirectoryException(sprintf('Directory \'%s\' does not exists (jvm-side)', $directory));
37
        }
38
39 9
        if (!$jFile->isDirectory()) {
40
            throw new Exception\InvalidDirectoryException(sprintf('Path \'%s\' is not a directory (jvm-side)', $directory));
41
        }
42
43 9
        return $jFile->canWrite();
44
    }
45
}
46