AbstractTestCase::forceFilePutContents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hivokas\LaravelHandlers\Tests;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Orchestra\Testbench\TestCase as OrchestraTestCase;
7
use Hivokas\LaravelHandlers\Providers\HandlersServiceProvider;
8
9
abstract class AbstractTestCase extends OrchestraTestCase
10
{
11
    /**
12
     * @var Filesystem
13
     */
14
    protected $files;
15
16
    /**
17
     * Define environment setup.
18
     *
19
     * @param  \Illuminate\Foundation\Application   $app
20
     *
21
     * @return void
22
     */
23
    protected function getEnvironmentSetUp($app)
24
    {
25
        $this->files = new Filesystem();
26
    }
27
28
    /**
29
     * Get package providers.
30
     *
31
     * @param \Illuminate\Foundation\Application $app
32
     * @return array
33
     */
34
    protected function getPackageProviders($app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

34
    protected function getPackageProviders(/** @scrutinizer ignore-unused */ $app)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        return [
37
            HandlersServiceProvider::class,
38
        ];
39
    }
40
41
    /**
42
     * Make the directory.
43
     *
44
     * @param  string  $path
45
     * @return string
46
     */
47
    protected function makeDirectory(string $path): string
48
    {
49
        if (! $this->files->isDirectory(dirname($path))) {
50
            $this->files->makeDirectory(dirname($path), 0777, true, true);
51
        }
52
53
        return $path;
54
    }
55
56
    /**
57
     * Put contents to file.
58
     *
59
     * @param string $path
60
     * @param string $contents
61
     * @param bool $lock
62
     */
63
    protected function forceFilePutContents(string $path, string $contents, bool $lock = false): void
64
    {
65
        $this->makeDirectory($path);
66
        $this->files->put($path, $contents, $lock);
67
    }
68
}
69