Completed
Push — master ( 48a5d3...028360 )
by Aydin
03:14
created

ExceptionalCoding::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace PhpSchool\LearnYouPhp\Exercise;
4
5
use Faker\Generator;
6
use PhpSchool\PhpWorkshop\Check\FunctionRequirementsCheck;
7
use PhpSchool\PhpWorkshop\Exercise\AbstractExercise;
8
use PhpSchool\PhpWorkshop\Exercise\CliExercise;
9
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
10
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
11
use PhpSchool\PhpWorkshop\Exercise\TemporaryDirectoryTrait;
12
use PhpSchool\PhpWorkshop\ExerciseCheck\FunctionRequirementsExerciseCheck;
13
use PhpSchool\PhpWorkshop\ExerciseCheck\StdOutExerciseCheck;
14
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
15
use Symfony\Component\Filesystem\Filesystem;
16
17 View Code Duplication
class ExceptionalCoding extends AbstractExercise implements
18
    ExerciseInterface,
19
    CliExercise,
20
    FunctionRequirementsExerciseCheck
21
{
22
    use TemporaryDirectoryTrait;
23
    
24
    /**
25
     * @var Filesystem
26
     */
27
    private $filesystem;
28
29
    /**
30
     * @var Generator
31
     */
32
    private $faker;
33
34
    /**
35
     * @param Filesystem $filesystem
36
     * @param Generator $faker
37
     */
38
    public function __construct(Filesystem $filesystem, Generator $faker)
39
    {
40
        $this->filesystem   = $filesystem;
41
        $this->faker        = $faker;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getName()
48
    {
49
        return "Exceptional Coding";
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getDescription()
56
    {
57
        return "Introduction to Exceptions";
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getArgs()
64
    {
65
        $this->filesystem->mkdir($this->getTemporaryPath());
66
67
        $fileCount = rand(2, 10);
68
        $realFiles = rand(1, $fileCount - 1);
69
70
        $files = [];
71
        foreach (range(1, $fileCount) as $index) {
72
            $file = sprintf('%s/%s.txt', $this->getTemporaryPath(), $this->faker->uuid);
73
            if ($index <= $realFiles) {
74
                $this->filesystem->touch($file);
75
            }
76
            $files[] = $file;
77
        }
78
79
        return $files;
80
    }
81
82
    /**
83
     * @return void
84
     */
85
    public function tearDown()
86
    {
87
        $this->filesystem->remove($this->getTemporaryPath());
88
    }
89
90
    /**
91
     * @return string[]
92
     */
93
    public function getRequiredFunctions()
94
    {
95
        return [];
96
    }
97
98
    /**
99
     * @return string[]
100
     */
101
    public function getBannedFunctions()
102
    {
103
        return ['array_filter', 'file_exists'];
104
    }
105
106
    /**
107
     * @return ExerciseType
108
     */
109
    public function getType()
110
    {
111
        return ExerciseType::CLI();
112
    }
113
114
    /**
115
     * @param ExerciseDispatcher $dispatcher
116
     */
117
    public function configure(ExerciseDispatcher $dispatcher)
118
    {
119
        $dispatcher->requireCheck(FunctionRequirementsCheck::class, $dispatcher::CHECK_AFTER);
120
    }
121
}
122