Issues (59)

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.

AggregateRepository.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
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
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
namespace Cubiche\Domain\EventSourcing;
13
14
use Cubiche\Domain\EventPublisher\DomainEventPublisher;
15
use Cubiche\Domain\EventSourcing\Event\PostPersistEvent;
16
use Cubiche\Domain\EventSourcing\Event\PostRemoveEvent;
17
use Cubiche\Domain\EventSourcing\Event\PrePersistEvent;
18
use Cubiche\Domain\EventSourcing\Event\PreRemoveEvent;
19
use Cubiche\Domain\EventSourcing\EventStore\EventStoreInterface;
20
use Cubiche\Domain\EventSourcing\EventStore\EventStream;
21
use Cubiche\Domain\EventSourcing\Utils\NameResolver;
22
use Cubiche\Domain\Model\IdInterface;
23
use Cubiche\Domain\Repository\RepositoryInterface;
24
25
/**
26
 * AggregateRepository class.
27
 *
28
 * @author Ivannis Suárez Jerez <[email protected]>
29
 */
30
class AggregateRepository implements RepositoryInterface
31
{
32
    /**
33
     * @var EventStoreInterface
34
     */
35
    protected $eventStore;
36
37
    /**
38
     * @var string
39
     */
40
    protected $aggregateClassName;
41
42
    /**
43
     * AggregateRepository constructor.
44
     *
45
     * @param EventStoreInterface $eventStore
46
     * @param string              $aggregateClassName
47
     */
48
    public function __construct(EventStoreInterface $eventStore, $aggregateClassName)
49
    {
50
        $this->eventStore = $eventStore;
51
        $this->aggregateClassName = $aggregateClassName;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function get(IdInterface $id)
58
    {
59
        $eventStream = $this->loadHistory($id);
60
61
        if ($eventStream !== null) {
62
            return call_user_func(
63
                array($this->aggregateClassName, 'loadFromHistory'),
64
                $eventStream
65
            );
66
        }
67
68
        return;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function persist($element)
75
    {
76 View Code Duplication
        if (!$element instanceof EventSourcedAggregateRootInterface) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            throw new \InvalidArgumentException(sprintf(
78
                'The object must be an instance of %s. Instance of %s given',
79
                EventSourcedAggregateRootInterface::class,
80
                is_object($element) ? get_class($element) : gettype($element)
81
            ));
82
        }
83
84
        $this->saveHistory($element);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function persistAll($elements)
91
    {
92
        foreach ($elements as $element) {
93
            $this->persist($element);
94
        }
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function remove($element)
101
    {
102 View Code Duplication
        if (!$element instanceof EventSourcedAggregateRootInterface) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
            throw new \InvalidArgumentException(sprintf(
104
                'The object must be an instance of %s. Instance of %s given',
105
                EventSourcedAggregateRootInterface::class,
106
                is_object($element) ? get_class($element) : gettype($element)
107
            ));
108
        }
109
110
        DomainEventPublisher::publish(new PreRemoveEvent($element));
111
112
        // remove the event stream
113
        $this->eventStore->remove($this->streamName($element->id()));
114
115
        DomainEventPublisher::publish(new PostRemoveEvent($element));
116
    }
117
118
    /**
119
     * Load a aggregate history from the storage.
120
     *
121
     * @param IdInterface $id
122
     *
123
     * @return EventStream|null
124
     */
125
    protected function loadHistory(IdInterface $id)
126
    {
127
        return $this->eventStore->load($this->streamName($id));
128
    }
129
130
    /**
131
     * Save the aggregate history.
132
     *
133
     * @param EventSourcedAggregateRootInterface $aggregateRoot
134
     */
135
    protected function saveHistory(EventSourcedAggregateRootInterface $aggregateRoot)
136
    {
137
        $recordedEvents = $aggregateRoot->recordedEvents();
138
        if (count($recordedEvents) > 0) {
139
            DomainEventPublisher::publish(new PrePersistEvent($aggregateRoot));
140
141
            // clear events
142
            $aggregateRoot->clearEvents();
143
144
            // create the eventStream and persist it
145
            $eventStream = new EventStream(
146
                $this->streamName($aggregateRoot->id()),
147
                $aggregateRoot->id(),
148
                $recordedEvents
149
            );
150
151
            $this->eventStore->persist($eventStream);
152
153
            DomainEventPublisher::publish(new PostPersistEvent($aggregateRoot, $eventStream));
154
        }
155
    }
156
157
    /**
158
     * @param IdInterface $id
159
     *
160
     * @return string
161
     */
162
    protected function streamName(IdInterface $id)
163
    {
164
        return NameResolver::resolve($this->aggregateClassName, $id);
165
    }
166
}
167