Issues (28)

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.

src/Domain/Aggregate.php (3 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 namespace C4tech\RayEmitter\Domain;
2
3
use C4tech\RayEmitter\Contracts\Domain\Aggregate as AggregateInterface;
4
use C4tech\RayEmitter\Contracts\Domain\Command as CommandInterface;
5
use C4tech\RayEmitter\Contracts\Domain\Event as EventInterface;
6
use C4tech\RayEmitter\Contracts\Event\Collection as EventCollectionInterface;
7
use C4tech\RayEmitter\Exceptions\CommandHandlerMissing;
8
use C4tech\RayEmitter\Exceptions\EventHandlerMissing;
9
use Illuminate\Support\Facades\Config;
10
11
abstract class Aggregate implements AggregateInterface
12
{
13
    /**
14
     * Aggregate root entity.
15
     * @var AggregateRootInterface
16
     */
17
    protected $root;
18
19
    /**
20
     * Event sequence counter.
21
     * @var integer
22
     */
23
    protected $sequence = -1;
24
25
    /**
26
     * @inheritDoc
27
     */
28 2 View Code Duplication
    public function apply(EventInterface $event)
0 ignored issues
show
This method seems to be duplicated in 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...
29
    {
30 2
        $method = $this->createMethodName('apply', $event);
31
32 2
        if (!method_exists($this, $method)) {
33 1
            throw new EventHandlerMissing(
34 1
                sprintf(
35 1
                    'Command %s does not have a handler for its expected aggregate %s',
36 1
                    get_class($event),
37 1
                    get_class($this)
38 1
                ),
39
                501
40 1
            );
41
        }
42
43 1
        $this->$method($event);
44 1
    }
45
46
    /**
47
     * Create Method Name
48
     *
49
     * Generate a method name using a configurable prefix and an object's class basename.
50
     * @param  string $prefix_key     The key from the configuration to lookup the appropriate prefix.
51
     * @param  object $object         The object which shall be reduced to its class basename.
52
     * @param  string $prefix_default The default prefix.
53
     * @return string                 The method name to use.
54
     */
55 2
    protected function createMethodName($prefix_key, $object, $prefix_default = null)
56
    {
57 2
        if (!$prefix_default) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $prefix_default of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
58 1
            $prefix_default = $prefix_key;
59 1
            $prefix_key .= '_prefix';
60 1
        }
61
62 2
        $prefix = Config::get('ray_emitter.' . $prefix_key, $prefix_default);
63 2
        $base = class_basename($object);
64
65 2
        return $prefix . $base;
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 1
    public function getEntity()
72
    {
73 1
        return $this->root->makeEntity();
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79 1
    public function getId()
80
    {
81 1
        return $this->root->getId();
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87 3
    public function getSequence()
88
    {
89 3
        return $this->sequence;
90
    }
91
92
    /**
93
     * @inheritDoc
94
     */
95 2 View Code Duplication
    public function handle(CommandInterface $command)
0 ignored issues
show
This method seems to be duplicated in 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...
96
    {
97 2
        $method = $this->createMethodName('handle', $command);
98
99 2
        if (!method_exists($this, $method)) {
100 1
            throw new CommandHandlerMissing(
101 1
                sprintf(
102 1
                    'Command %s does not have a handler for its expected aggregate %s',
103 1
                    get_class($command),
104 1
                    get_class($this)
105 1
                ),
106
                501
107 1
            );
108
        }
109
110 1
        return $this->$method($command);
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116
    public function hydrate(EventCollectionInterface $events)
117
    {
118 1
        $events->each(function (EventInterface $event) {
119 1
            $this->apply($event);
120 1
            $this->sequence++;
121 1
        });
122 1
    }
123
124
    /**
125
     * Magic Getter
126
     *
127
     * Expose getter methods on the Aggregate and Aggregate Root as properties.
128
     * @param  string $property Requested "property"
129
     * @return mixed
130
     */
131 2
    public function __get($property)
132
    {
133 2
        $method = 'get' . studly_case($property);
134
135 2
        if (method_exists($this, $method)) {
136 1
            return $this->$method();
137
        }
138
139 1
        return $this->root->$property;
140
    }
141
}
142