GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e682e0...ff0450 )
by Odiseo
05:11
created

BlogArticleCategoryExampleFactory::getLocales()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusBlogPlugin\Fixture\Factory;
6
7
use Faker\Factory;
8
use Odiseo\BlogBundle\Model\ArticleCategoryInterface;
9
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
10
use Sylius\Component\Core\Formatter\StringInflector;
11
use Sylius\Component\Locale\Model\LocaleInterface;
12
use Sylius\Component\Resource\Factory\FactoryInterface;
13
use Sylius\Component\Resource\Repository\RepositoryInterface;
14
use Symfony\Component\OptionsResolver\Options;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
17
final class BlogArticleCategoryExampleFactory extends AbstractExampleFactory
18
{
19
    /** @var FactoryInterface */
20
    private $articleCategoryFactory;
21
22
    /** @var RepositoryInterface */
23
    private $localeRepository;
24
25
    /** @var \Faker\Generator */
26
    private $faker;
27
28
    /** @var OptionsResolver */
29
    private $optionsResolver;
30
31
    public function __construct(
32
        FactoryInterface $articleCategoryFactory,
33
        RepositoryInterface $localeRepository
34
    ) {
35
        $this->articleCategoryFactory = $articleCategoryFactory;
36
        $this->localeRepository = $localeRepository;
37
38
        $this->faker = Factory::create();
39
        $this->optionsResolver = new OptionsResolver();
40
41
        $this->configureOptions($this->optionsResolver);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function create(array $options = []): ArticleCategoryInterface
48
    {
49
        $options = $this->optionsResolver->resolve($options);
50
51
        /** @var ArticleCategoryInterface $articleCategory */
52
        $articleCategory = $this->articleCategoryFactory->createNew();
53
        $articleCategory->setCode($options['code']);
54
        $articleCategory->setEnabled($options['enabled']);
55
56
        foreach ($this->getLocales() as $localeCode) {
57
            $articleCategory->setCurrentLocale((string) $localeCode);
58
            $articleCategory->setFallbackLocale((string) $localeCode);
59
60
            $articleCategory->setTitle($options['title']);
61
            $articleCategory->setSlug($options['slug']);
62
        }
63
64
        return $articleCategory;
65
    }
66
67
    private function getLocales(): \Generator
68
    {
69
        /** @var LocaleInterface[] $locales */
70
        $locales = $this->localeRepository->findAll();
71
        foreach ($locales as $locale) {
72
            yield $locale->getCode();
73
        }
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    protected function configureOptions(OptionsResolver $resolver): void
80
    {
81
        $resolver
82
            ->setDefault('code', function (Options $options): string {
83
                return StringInflector::nameToCode((string) $options['title']);
84
            })
85
            ->setDefault('enabled', function (Options $options): bool {
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

85
            ->setDefault('enabled', function (/** @scrutinizer ignore-unused */ Options $options): bool {

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...
86
                return $this->faker->boolean(90);
87
            })
88
            ->setAllowedTypes('enabled', 'bool')
89
            ->setDefault('title', function (Options $options): string {
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

89
            ->setDefault('title', function (/** @scrutinizer ignore-unused */ Options $options): string {

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...
90
                return $this->faker->words(3, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->faker->words(3, true) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
91
            })
92
            ->setDefault('slug', function (Options $options): string {
93
                return StringInflector::nameToCode((string) $options['title']);
94
            })
95
        ;
96
    }
97
}
98