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.

Issues (28)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Admin/ImportableAdminTrait.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Sigmapix\Sonata\ImportBundle\Admin;
4
5
use Port\Steps\Step\ValueConverterStep;
6
use Port\Steps\StepAggregator;
7
use Port\ValueConverter\DateTimeValueConverter;
8
use Sigmapix\Sonata\ImportBundle\Form\Type\ImportFieldChoiceType;
9
use Sonata\AdminBundle\Admin\AbstractAdmin;
10
use Sonata\AdminBundle\Admin\Pool;
11
use Sonata\AdminBundle\Builder\FormContractorInterface;
12
use Sonata\AdminBundle\Form\FormMapper;
13
use Sonata\AdminBundle\Route\RouteCollection;
14
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
15
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
18
use Symfony\Component\Form\Form;
19
use Symfony\Component\Form\FormBuilder;
20
use Symfony\Component\Form\FormBuilderInterface;
21
use Symfony\Component\HttpFoundation\File\UploadedFile;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\HttpFoundation\Response;
24
use Symfony\Component\Translation\TranslatorInterface;
25
26
/**
27
 * Trait ImportableAdminTrait.
28
 */
29
trait ImportableAdminTrait
30
{
31
    /**
32
     * Options to set to the form (ie, validation_groups).
33
     *
34
     * @var array
35
     */
36
    protected $formOptions = [];
37
    /**
38
     * @var Form
39
     */
40
    private $importForm;
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    abstract public function getClass();
46
47
    /**
48
     * @return Pool
49
     */
50
    abstract public function getConfigurationPool();
51
52
    /**
53
     * @return FormContractorInterface
54
     */
55
    abstract public function getFormContractor();
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @throws \ReflectionException
61
     */
62
    public function getImportFormBuilder(array $headers)
63
    {
64
        $class = $this->hasActiveSubClass() ? $this->getActiveSubClass() : $this->getClass();
0 ignored issues
show
It seems like hasActiveSubClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
It seems like getActiveSubClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
65
        if ((new \ReflectionClass($class))->isAbstract()) {
66
            // If $class is Abstract, then use the first one.
67
            // Developers should then instantiate the good class by overriding DoctrineWrite::writeItem()
68
            $class = array_values($this->getSubClasses())[0];
0 ignored issues
show
It seems like getSubClasses() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
        }
70
71
        $this->formOptions['data_class'] = $class;
72
73
        $formBuilder = $this->getFormContractor()->getFormBuilder(
74
            'import_form', $this->formOptions
75
        );
76
77
        $this->defineImportFormBuilder($formBuilder, $headers);
78
79
        return $formBuilder;
80
    }
81
82
    /**
83
     * @param FormBuilderInterface $formBuilder
84
     * @param array                $headers
85
     *                                          todo: use defineFormBuilder for import Action and upload Action
86
     */
87
    public function defineImportFormBuilder(FormBuilderInterface $formBuilder, array $headers)
88
    {
89
        /** @var AbstractAdmin $this */
90
        $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this);
91
        $this->configureImportFields($mapper);
0 ignored issues
show
The method configureImportFields() does not exist on Sonata\AdminBundle\Admin\AbstractAdmin. Did you maybe mean configure()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
92
        /** @var ContainerInterface $container */
93
        $container = $this->getConfigurationPool()->getContainer();
94
        $trans = $container->get('translator');
95
96
        $oldValue = ini_get('mbstring.substitute_character');
97
        ini_set('mbstring.substitute_character', 'none');
98
        foreach ($formBuilder as $field) {
99
            /* @var FormBuilder $field */
100
            if ($field->getType()->getInnerType() instanceof EntityType) {
101
                continue;
102
            }
103
            $propertyPath = $field->getPropertyPath();
104
            if ($propertyPath && $propertyPath->getLength() > 1) {
105
                $mapper->add(
106
                    (string) $propertyPath, ImportFieldChoiceType::class, [
107
                    'choices' => $headers,
108
                    'data' => $this->nearest($field->getOption('label'), $headers, $trans),
0 ignored issues
show
The method nearest() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
                    'mapped' => false,
110
                    'label' => $field->getOption('label'),
111
                ]);
112
            } elseif ('id' === (string) $propertyPath) {
113
                $mapper->add($field->getName(), ImportFieldChoiceType::class, [
114
                    'choices' => $headers,
115
                    'data' => $this->nearest($field->getOption('label'), $headers, $trans),
0 ignored issues
show
The method nearest() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
                    'mapped' => false,
117
                    'label' => $field->getOption('label'),
118
                ]);
119
            } else {
120
                $mapper->add($field->getName(), ImportFieldChoiceType::class, [
121
                    'choices' => $headers,
122
                    'data' => $this->nearest($field->getOption('label'), $headers, $trans, $field->getOption('translation_domain')),
0 ignored issues
show
The method nearest() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
                    'mapped' => $field->getOption('mapped'),
124
                    'label' => $field->getOption('label'),
125
                    'label_format' => $field->getOption('label_format'), // This will be used for DateTimeConverter
126
                    'translation_domain' => $field->getOption('translation_domain'),
127
                ]);
128
            }
129
        }
130
        ini_set('mbstring.substitute_character', $oldValue);
131
        $formBuilder->add('import', SubmitType::class);
132
        $this->attachInlineValidator();
0 ignored issues
show
The method attachInlineValidator() cannot be called from this context as it is declared protected in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
133
    }
134
135
    /**
136
     * @param $admin
137
     * @param null $object
138
     *
139
     * @return mixed
140
     */
141
    public function configureActionButtons($admin, $object = null)
142
    {
143
        $buttonList = parent::configureActionButtons($admin, $object);
144
        $buttonList['import'] = [
145
            'template' => 'SigmapixSonataImportBundle:Button:import_button.html.twig',
146
        ];
147
        return $buttonList;
148
    }
149
150
    /**
151
     * @param array $headers
152
     *
153
     * @throws \ReflectionException
154
     *
155
     * @return Form
156
     */
157
    public function getImportForm(array $headers)
158
    {
159
        $this->buildImportForm($headers);
160
161
        return $this->importForm;
162
    }
163
164
    /**
165
     * @param StepAggregator $workflow
166
     */
167
    public function configureImportSteps(StepAggregator $workflow)
168
    {
169
        $dateTimeFields = [];
170
        foreach ($this->importForm as $f) {
171
            /** @var Form $f */
172
            /** @var FieldDescription $fieldOptions */
173
            $fieldOptions = $f->getConfig()->getOption('sonata_field_description');
174
            if ($fieldOptions && ('datetime' === $fieldOptions->getMappingType() || 'date' === $fieldOptions->getMappingType() || $f->getConfig()->getOption('label_format'))) {
175
                $dateTimeFields[$f->getName()] = $f->getConfig()->getOption('label_format');
176
            }
177
        }
178
        $converterStep = new ValueConverterStep();
179
        foreach ($dateTimeFields as $dateTimeField => $dateTimeFormat) {
180
            $converter = new DateTimeValueConverter($dateTimeFormat);
181
            $converterStep->add('['.$dateTimeField.']', $converter);
182
        }
183
        $workflow->addStep($converterStep);
184
    }
185
186
    /**
187
     * This method can be overloaded in your Admin service.
188
     * It's called from importAction.
189
     *
190
     * @param Request $request
191
     * @param Form    $form
192
     *
193
     * @return Response|null
194
     */
195
    public function preImport(Request $request, Form $form)
0 ignored issues
show
The parameter $request is not used and could be removed.

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

Loading history...
The parameter $form is not used and could be removed.

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

Loading history...
196
    {
197
    }
198
199
    /**
200
     * This method can be overloaded in your Admin service.
201
     * It's called from importAction.
202
     *
203
     * @param Request      $request
204
     * @param UploadedFile $file
205
     * @param Form         $form
206
     * @param mixed        $results
207
     *
208
     * @return Response|null
209
     */
210
    public function postImport(Request $request, UploadedFile $file, Form $form, $results)
0 ignored issues
show
The parameter $request is not used and could be removed.

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

Loading history...
The parameter $file is not used and could be removed.

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

Loading history...
The parameter $form is not used and could be removed.

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

Loading history...
The parameter $results is not used and could be removed.

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

Loading history...
211
    {
212
    }
213
214
    /**
215
     * @param FormMapper $formMapper
216
     */
217
    abstract protected function configureImportFields(FormMapper $formMapper);
218
219
    /**
220
     * Attach the inline validator to the model metadata, this must be done once per admin.
221
     */
222
    abstract protected function attachInlineValidator();
223
224
    /**
225
     * @param RouteCollection $collection
226
     */
227
    protected function configureRoutes(RouteCollection $collection)
228
    {
229
        /* @var AbstractAdmin $this */
230
        $collection
231
                ->add('import', 'upload/{fileName}')
232
                ->add('upload')
233
        ;
234
    }
235
236
    /**
237
     * @param array $headers
238
     *
239
     * @throws \ReflectionException
240
     */
241
    protected function buildImportForm(array $headers)
242
    {
243
        if ($this->importForm) {
244
            return;
245
        }
246
        $this->importForm = $this->getImportFormBuilder($headers)->getForm();
247
    }
248
249
    /**
250
     * @param $input
251
     * @param $words
252
     * @param TranslatorInterface $trans
253
     * @param string              $domain
254
     *
255
     * @return string
256
     */
257
    private function nearest($input, $words, TranslatorInterface $trans, $domain = null)
0 ignored issues
show
This method is not used, and could be removed.
Loading history...
258
    {
259
        // TODO $input should be the $field, to try both 'name' and 'propertyPath' attributes
260
        $domain = $domain ?: 'messages';
261
        $closest = '';
262
        $shortest = -1;
263
264
        foreach ($words as $word) {
265
            $wordASCII = mb_convert_encoding($word, 'ASCII');
266
            $lev = levenshtein($input, $wordASCII);
267
            $levCase = levenshtein(strtolower($input), strtolower($wordASCII));
268
            $levTrans = levenshtein($trans->trans($input, [], $domain), $wordASCII);
269
            $lev = min([$lev, $levCase, $levTrans]);
270
            if (0 === $lev) {
271
                $closest = $word;
272
                break;
273
            }
274
            if ($lev <= $shortest || $shortest < 0) {
275
                $closest = $word;
276
                $shortest = $lev;
277
            }
278
        }
279
280
        return $closest;
281
    }
282
}
283