Issues (80)

Security Analysis    no request data  

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.

Loader/YamlLoader.php (2 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 Khepin\YamlFixturesBundle\Loader;
4
5
use Khepin\YamlFixturesBundle\Fixture\YamlAclFixture;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
8
use Symfony\Component\Yaml\Yaml;
9
use Symfony\Component\HttpKernel\KernelInterface;
10
11
class YamlLoader
12
{
13
    protected $bundles;
14
15
    /**
16
     *
17
     * @var type
18
     */
19
    protected $kernel;
20
21
    /**
22
     * Doctrine entity manager
23
     * @var type
24
     */
25
    protected $object_manager;
26
27
    protected $acl_manager = null;
28
29
    /**
30
     * Array of all yml files containing fixtures that should be loaded
31
     * @var type
32
     */
33
    protected $fixture_files = array();
34
35
    /**
36
     * Maintains references to already created objects
37
     * @var type
38
     */
39
    protected $references = array();
40
41
    /**
42
     * The directory containing the fixtures files
43
     *
44
     * @var string
45
     */
46
    protected $directory;
47
48
    public function __construct(KernelInterface $kernel, $bundles, $directory)
49
    {
50
        $this->bundles = $bundles;
51
        $this->kernel = $kernel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $kernel of type object<Symfony\Component...Kernel\KernelInterface> is incompatible with the declared type object<Khepin\YamlFixturesBundle\Loader\type> of property $kernel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        $this->directory = $directory;
53
    }
54
55
    /**
56
     *
57
     * @param type $manager
58
     */
59
    public function setAclManager($manager = null)
60
    {
61
        $this->acl_manager = $manager;
62
    }
63
64
    /**
65
     * Returns a previously saved reference
66
     * @param  type $reference_name
67
     * @return type
68
     */
69
    public function getReference($reference_name)
70
    {
71
        return !is_null($reference_name) ? $this->references[$reference_name] : null;
72
    }
73
74
    /**
75
     * Sets a reference to an object
76
     * @param type $name
77
     * @param type $object
78
     */
79
    public function setReference($name, $object)
80
    {
81
        $this->references[$name] = $object;
82
    }
83
84
    /**
85
     * Gets all fixtures files
86
     */
87
    protected function loadFixtureFiles()
88
    {
89
        foreach ($this->bundles as $bundle) {
90
            $file = '*';
91
            if (strpos($bundle, '/')) {
92
                list($bundle, $file) = explode('/', $bundle);
93
            }
94
            $path = $this->kernel->locateResource('@' . $bundle);
95
            $files = glob($path . $this->directory . '/'.$file.'.yml');
96
            $this->fixture_files = array_unique(array_merge($this->fixture_files, $files));
0 ignored issues
show
Documentation Bug introduced by
It seems like array_unique(array_merge...fixture_files, $files)) of type array is incompatible with the declared type object<Khepin\YamlFixturesBundle\Loader\type> of property $fixture_files.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
        }
98
    }
99
100
    /**
101
     * Loads the fixtures file by file and saves them to the database
102
     */
103
    public function loadFixtures()
104
    {
105
        $this->loadFixtureFiles();
106
        foreach ($this->fixture_files as $file) {
107
            $fixture_data = Yaml::parse(file_get_contents($file));
108
            // if nothing is specified, we use doctrine orm for persistence
109
            $persistence = isset($fixture_data['persistence']) ? $fixture_data['persistence'] : 'orm';
110
111
            $persister = $this->getPersister($persistence);
112
            $manager = $persister->getManagerForClass($fixture_data['model']);
113
114
            $fixture = $this->getFixtureClass($persistence);
115
            $fixture = new $fixture($fixture_data, $this, $file);
116
            $fixture->load($manager, func_get_args());
117
        }
118
119
        if (!is_null($this->acl_manager)) {
120
            foreach ($this->fixture_files as $file) {
121
                $fixture = new YamlAclFixture($file, $this);
122
                $fixture->load($this->acl_manager, func_get_args());
123
            }
124
        }
125
    }
126
127
    /**
128
     * Remove all fixtures from the database
129
     */
130
    public function purgeDatabase($persistence, $databaseName = null, $withTruncate = false)
131
    {
132
        $purgetools = array(
133
            'orm'       => array(
134
                'purger'    => 'Doctrine\Common\DataFixtures\Purger\ORMPurger',
135
                'executor'  => 'Doctrine\Common\DataFixtures\Executor\ORMExecutor',
136
            ),
137
            'mongodb'   => array(
138
                'purger'    => 'Doctrine\Common\DataFixtures\Purger\MongoDBPurger',
139
                'executor'  => 'Doctrine\Common\DataFixtures\Executor\MongoDBExecutor',
140
            )
141
        );
142
        // Retrieve the correct purger and executor
143
        $purge_class = $purgetools[$persistence]['purger'];
144
        $executor_class = $purgetools[$persistence]['executor'];
145
146
        // Instanciate purger and executor
147
        $persister = $this->getPersister($persistence);
148
        $entityManagers = ($databaseName)
149
            ? array($persister->getManager($databaseName))
150
            : $persister->getManagers();
151
152
        foreach ($entityManagers as $entityManager) {
153
            $purger = new $purge_class($entityManager);
154
            if ($withTruncate && $purger instanceof ORMPurger) {
155
                $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
156
            }
157
            $executor = new $executor_class($entityManager, $purger);
158
            // purge
159
            $executor->purge();
160
        }
161
    }
162
163
    /*
164
     * Returns the doctrine persister for the given persistence layer
165
     * @return ManagerRegistry
166
     */
167
    public function getPersister($persistence)
168
    {
169
        $managers = array(
170
            'orm'       => 'doctrine',
171
            'mongodb'   => 'doctrine_mongodb',
172
        );
173
174
        return $this->kernel->getContainer()->get($managers[$persistence]);
175
    }
176
177
    /**
178
     * @return string classname
179
     */
180
    public function getFixtureClass($persistence)
181
    {
182
        $classes = array(
183
            'orm'       => 'Khepin\YamlFixturesBundle\Fixture\OrmYamlFixture',
184
            'mongodb'   => 'Khepin\YamlFixturesBundle\Fixture\MongoYamlFixture'
185
        );
186
187
        return $classes[$persistence];
188
    }
189
190
    /**
191
     * @return the service with given id
192
     */
193
    public function getService($service_id)
194
    {
195
        return $this->kernel->getContainer()->get($service_id);
196
    }
197
}
198