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/Event/Store.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 namespace C4tech\RayEmitter\Event;
2
3
use C4tech\RayEmitter\Contracts\Domain\Event as EventInterface;
4
use C4tech\RayEmitter\Contracts\Event\Store as StoreInterface;
5
use Illuminate\Support\Facades\Event as EventBus;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Store extends Model implements StoreInterface
9
{
10
    protected static $queue = [];
11
12
    /**
13
     * @inheritDoc
14
     */
15
    protected $table = 'event_store';
16
17
    /**
18
     * @inheritDoc
19
     */
20
    protected $fillable = [
21
        'identifier',
22
        'sequence',
23
        'event',
24
        'payload'
25
    ];
26
27
    /**
28
     * @inheritDoc
29
     */
30 1
    public function getFor($identifier)
31
    {
32 1
        $events = new Collection;
33
34 1
        $recorded_events = $this->newQuery()->forEntity($identifier)->get();
35 1
        foreach ($recorded_events as $record) {
36 1
            $events->append($this->restoreEvent($record));
37 1
        }
38
39 1
        return $events;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $events; (C4tech\RayEmitter\Event\Collection) is incompatible with the return type declared by the interface C4tech\RayEmitter\Contracts\Event\Store::getFor of type C4tech\RayEmitter\Contra...tracts\Event\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
40
    }
41
42 1
    public function replayAll()
43
    {
44 1
        $records = $this->all();
45
46 1
        $records->each(function ($record) {
47 1
            $event = $this->restoreEvent($record);
48 1
            EventBus::fire('replay:' . $record->event, [$event]);
49 1
        });
50 1
    }
51
52
    /**
53
     * Restore Event
54
     *
55
     * Unserialize saved record back into an Event.
56
     * @param  static         $record Event Store model record
57
     * @return EventInterface
58
     */
59 1
    protected function restoreEvent($record)
60
    {
61 1
        $class = $record->event;
0 ignored issues
show
The property event does not exist on object<C4tech\RayEmitter\Event\Store>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
63 1
        return $class::unserialize($record);
64
    }
65
66
67
    /**
68
     * @inheritDoc
69
     */
70 1
    public function saveEvent(EventInterface $event)
71
    {
72 1
        $class = get_class($event);
73
        $record = [
74 1
            'event'      => $class,
75 1
            'identifier' => $event->getId(),
76 1
            'payload'    => $event->serialize(),
77 1
            'sequence'   => $this->newQuery()
78 1
                                ->forEntity($event->getId())
79 1
                                ->count()
80 1
        ];
81 1
        static::create($record);
82
83 1
        self::$queue[] = [
84 1
            'event' => $class,
85 1
            'payload' => [$event]
86 1
        ];
87 1
        EventBus::fire('save:' . $class, [$event]);
88 1
    }
89
90
    /**
91
     * Save Queue
92
     *
93
     * Persist all queued Events into Event Store.
94
     * @return void
95
     */
96 1
    public function publishQueue()
97
    {
98 1
        foreach (static::$queue as $record) {
99 1
            EventBus::fire('publish:' . $record['event'], $record['payload']);
100 1
        }
101
102 1
        static::$queue = [];
103 1
    }
104
105
    /**
106
     * Scope: For Entity
107
     *
108
     * Query scope for Entity identifier.
109
     * @param  Query  $query      Query Builder
110
     * @param  string $identifier Entity identifier
111
     * @return Query
112
     */
113 1
    public function scopeForEntity($query, $identifier)
114
    {
115 1
        return $query->where('identifier', '=', $identifier);
116
    }
117
}
118