FSObject   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 2
dl 0
loc 62
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A flightcontrol() 0 4 1
A filesystem() 0 4 1
A path() 0 4 1
A name() 0 5 1
A mimetype() 0 4 1
A normalize() 0 7 2
isFile() 0 1 ?
1
<?php
2
/******************************************************************************
3
 * An iterator interface over the Leagues flysystem.
4
 * Copyright (c) 2021, 2015 Richard Klees <[email protected]>
5
 *
6
 * This software is licensed under GPLv3. You should have received
7
 * a copy of the along with the code.
8
 */
9
10
namespace Lechimp\Flightcontrol;
11
12
/**
13
 * Some object on the filesystem.
14
 */
15
abstract class FSObject
16
{
17
    /**
18
     * @var Flightcontrol
19
     */
20
    protected $flightcontrol;
21
22
    /**
23
     * @var \League\Flysystem\Filesystem
24
     */
25
    protected $filesystem;
26
27
    /**
28
     * @var string
29
     */
30
    protected $path;
31
32 66
    public function __construct(Flightcontrol $flightcontrol, string $path)
33
    {
34 66
        assert(is_string($path));
35 66
        $this->flightcontrol = $flightcontrol;
36 66
        $this->path = self::normalize($path);
37 66
    }
38
39 45
    public function flightcontrol() : Flightcontrol
40
    {
41 45
        return $this->flightcontrol;
42
    }
43
44 52
    public function filesystem() : \League\Flysystem\Filesystem
45
    {
46 52
        return $this->flightcontrol->filesystem();
47
    }
48
49 58
    public function path() : string
50
    {
51 58
        return $this->path;
52
    }
53
54 52
    public function name() : string
55
    {
56 52
        $parts = explode("/", $this->path);
57 52
        return end($parts);
58
    }
59
60
    public function mimetype() : ?string
61
    {
62
        return $this->filesystem->mimetype($this->path);
63
    }
64
65
    // Helper
66
67 66
    private static function normalize(string $path) : string
68
    {
69 66
        if (substr($path, -1) == "/") {
70 3
            $path = substr($path, 0, strlen($path) - 1);
71
        }
72 66
        return $path;
73
    }
74
75
    abstract public function isFile() : bool;
76
}
77