Issues (3)

src/Fixture/FileFixture.php (1 issue)

Labels
Severity
1
<?php
2
3
/*
4
 * This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
5
 *
6
 * (c) Monsieur Biz <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace MonsieurBiz\SyliusRichEditorPlugin\Fixture;
15
16
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FixtureFileUploaderInterface;
17
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
18
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
19
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
20
use Symfony\Component\HttpFoundation\File\UploadedFile;
21
22
final class FileFixture extends AbstractFixture implements FixtureInterface
23
{
24
    /**
25
     * @var FixtureFileUploaderInterface
26
     */
27
    private FixtureFileUploaderInterface $uploader;
28
29
    /**
30
     * @param FixtureFileUploaderInterface $uploader
31
     */
32
    public function __construct(FixtureFileUploaderInterface $uploader)
33
    {
34
        $this->uploader = $uploader;
35
    }
36
37
    /**
38
     * @param array $options
39
     */
40
    public function load(array $options): void
41
    {
42
        foreach ($options['files'] as $data) {
43
            $file = new UploadedFile($data['source_path'], basename($data['source_path']));
44
            $this->uploader->upload($file, $data['target_path']);
45
        }
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getName(): string
52
    {
53
        return 'monsieurbiz_rich_editor_file';
54
    }
55
56
    /**
57
     * @param ArrayNodeDefinition $optionsNode
58
     */
59
    protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
60
    {
61
        /** @phpstan-ignore-next-line */
62
        $optionsNode
63
            ->children()
64
                ->arrayNode('files')
65
                    ->arrayPrototype()
66
                        ->children()
67
                            ->scalarNode('source_path')->cannotBeEmpty()->end()
68
                            ->scalarNode('target_path')->cannotBeEmpty()->end()
0 ignored issues
show
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

68
                            ->/** @scrutinizer ignore-call */ scalarNode('target_path')->cannotBeEmpty()->end()
Loading history...
69
                        ->end()
70
                    ->end()
71
                ->end()
72
            ->end()
73
        ;
74
    }
75
}
76