Completed
Push — master ( 6d4325...ab885c )
by Tom
04:09
created

getDocumentationLinks()   A

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 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Astrotomic\Stancy\Solutions;
4
5
use Facade\IgnitionContracts\RunnableSolution;
6
use Illuminate\Contracts\Filesystem\Filesystem;
7
use ReflectionClass;
8
use Spatie\Sheets\Facades\Sheets;
9
use Spatie\Sheets\Repositories\FilesystemRepository;
10
11
class AddSheetToCollectionSolution implements RunnableSolution
12
{
13
    /** @var string */
14
    protected $collection;
15
16
    /** @var string */
17
    protected $sheet;
18
19
    /** @var Filesystem|null */
20
    protected $filesystem;
21
22
    /** @var string|null */
23
    protected $extension;
24
25 3
    public function __construct(string $collection, string $sheet)
26
    {
27 3
        $this->collection = $collection;
28 3
        $this->sheet = $sheet;
29
30 3
        $this->copyPropertiesFromFilesystemRepository();
31 3
    }
32
33 1
    public function getSolutionTitle(): string
34
    {
35 1
        return 'The sheet is missing';
36
    }
37
38 1
    public function getSolutionDescription(): string
39
    {
40 1
        return "Add sheet `{$this->sheet}` to collection `{$this->collection}`.";
41
    }
42
43 1
    public function getRunButtonText(): string
44
    {
45 1
        return 'Add sheet file';
46
    }
47
48 1
    public function getSolutionActionDescription(): string
49
    {
50 1
        return 'Pressing the button below will try to add the sheet file to the collection filesystem.';
51
    }
52
53 1
    public function getRunParameters(): array
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Solutions\AddSheetToCollectionSolution::getRunParameters() does not have @return annotation for its traversable return value.
Loading history...
54
    {
55 1
        return [];
56
    }
57
58 1
    public function getDocumentationLinks(): array
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Solutions\AddSheetToCollectionSolution::getDocumentationLinks() does not have @return annotation for its traversable return value.
Loading history...
59
    {
60 1
        return [];
61
    }
62
63 2
    public function run(array $parameters = []): bool
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Solutions\AddSheetToCollectionSolution::run() does not have @param annotation for its traversable parameter $parameters.
Loading history...
introduced by
Unused parameter $parameters.
Loading history...
64
    {
65 2
        if ($this->filesystem === null) {
66
            return false;
67
        }
68
69 2
        if ($this->extension === null) {
70
            return false;
71
        }
72
73 2
        return $this->filesystem->put($this->sheet.'.'.$this->extension, '');
74
    }
75
76 3
    protected function copyPropertiesFromFilesystemRepository(): void
77
    {
78 3
        $repository = Sheets::collection($this->collection);
79
80 3
        if (!$repository instanceof FilesystemRepository) {
0 ignored issues
show
introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
81
            return;
82
        }
83
84 3
        $repositoryReflection = new ReflectionClass($repository);
85
86 3
        $filesystemProperty = $repositoryReflection->getProperty('filesystem');
87 3
        $filesystemProperty->setAccessible(true);
88 3
        $this->filesystem = $filesystemProperty->getValue($repository);
89
90 3
        $extensionProperty = $repositoryReflection->getProperty('extension');
91 3
        $extensionProperty->setAccessible(true);
92 3
        $this->extension = $extensionProperty->getValue($repository);
93 3
    }
94
}
95