Issues (1191)

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.

src/Entry/EntryPresenter.php (11 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 Anomaly\Streams\Platform\Entry;
2
3
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
4
use Anomaly\Streams\Platform\Model\EloquentModel;
5
use Anomaly\Streams\Platform\Model\EloquentPresenter;
6
use Anomaly\Streams\Platform\Support\Value;
7
8
/**
9
 * Class EntryPresenter
10
 *
11
 * @link    http://pyrocms.com/
12
 * @author  PyroCMS, Inc. <[email protected]>
13
 * @author  Ryan Thompson <[email protected]>
14
 */
15
class EntryPresenter extends EloquentPresenter
16
{
17
18
    /**
19
     * The resource object.
20
     * This is for IDE hinting.
21
     *
22
     * @var EntryInterface|EloquentModel
23
     */
24
    protected $object;
25
26
    /**
27
     * Return the date string for created at.
28
     *
29
     * @return string
30
     */
31
    public function createdAtDate()
32
    {
33
        return $this->object->created_at
34
            ->setTimezone(config('app.timezone'))
35
            ->format(config('streams::datetime.date_format'));
36
    }
37
38
    /**
39
     * Return the datetime string for created at.
40
     *
41
     * @return string
42
     */
43
    public function createdAtDatetime()
44
    {
45
        return $this->object->created_at
46
            ->setTimezone(config('app.timezone'))
47
            ->format(config('streams::datetime.date_format') . ' ' . config('streams::datetime.time_format'));
48
    }
49
50
    /**
51
     * Return the date string for updated at.
52
     *
53
     * @return string
54
     */
55
    public function updatedAtDate()
56
    {
57
        return $this->object->updated_at
58
            ->setTimezone(config('app.timezone'))
59
            ->format(config('streams::datetime.date_format'));
60
    }
61
62
    /**
63
     * Return the datetime string for updated at.
64
     *
65
     * @return string
66
     */
67
    public function updatedAtDatetime()
68
    {
69
        return $this->object->updated_at
70
            ->setTimezone(config('app.timezone'))
71
            ->format(config('streams:datetime.date_format') . ' ' . config('streams:datetime.time_format'));
72
    }
73
74
    /**
75
     * Return a label.
76
     *
77
     * @param         $text
78
     * @param  string $context
79
     * @param  string $size
80
     * @return string
81
     */
82
    public function label($text = null, $context = null, $size = null)
83
    {
84
        if (!$text) {
85
            $text = $this->object->getTitleName();
86
        }
87
88
        if (!$context) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $context 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...
89
            $context = 'default';
90
        }
91
92
        if (!$size) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $size 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...
93
            $size = 'sm';
94
        }
95
96
        /* @var Value $value */
97
        $value = app(Value::class);
98
99
        $text = $value->make($text, $this->object);
100
101
        if (trans()->has($text) && is_string(trans($text))) {
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Translation\TranslatorInterface as the method has() does only exist in the following implementations of said interface: Illuminate\Translation\Translator.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
102
            $text = trans($text);
103
        }
104
105
        return '<span class="tag tag-' . $context . ' tag-' . $size . '">' . $text . '</span>';
106
    }
107
108
    /**
109
     * Return the edit URL.
110
     *
111
     * @return string
112
     */
113 View Code Duplication
    public function editUrl()
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...
114
    {
115
        return url(
116
            implode(
117
                '/',
118
                array_unique(
119
                    array_filter(
120
                        [
121
                            'admin',
122
                            $this->object->getStreamNamespace(),
0 ignored issues
show
The method getStreamNamespace does only exist in Anomaly\Streams\Platform...Contract\EntryInterface, but not in Anomaly\Streams\Platform\Model\EloquentModel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
123
                            $this->object->getStreamSlug(),
0 ignored issues
show
The method getStreamSlug does only exist in Anomaly\Streams\Platform...Contract\EntryInterface, but not in Anomaly\Streams\Platform\Model\EloquentModel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
124
                            'edit',
125
                            $this->object->getId(),
126
                        ]
127
                    )
128
                )
129
            )
130
        );
131
    }
132
133
    /**
134
     * Return the edit link.
135
     *
136
     * @return string
137
     */
138
    public function editLink()
139
    {
140
        return app('html')->link($this->editUrl(), $this->object->{$this->object->getTitleName()});
141
    }
142
143
    /**
144
     * Return the view URL.
145
     *
146
     * @return string
147
     */
148 View Code Duplication
    public function viewUrl()
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...
149
    {
150
        return url(
151
            implode(
152
                '/',
153
                array_unique(
154
                    array_filter(
155
                        [
156
                            'admin',
157
                            $this->object->getStreamNamespace(),
0 ignored issues
show
The method getStreamNamespace does only exist in Anomaly\Streams\Platform...Contract\EntryInterface, but not in Anomaly\Streams\Platform\Model\EloquentModel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
158
                            $this->object->getStreamSlug(),
0 ignored issues
show
The method getStreamSlug does only exist in Anomaly\Streams\Platform...Contract\EntryInterface, but not in Anomaly\Streams\Platform\Model\EloquentModel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
159
                            'view',
160
                            $this->object->getId(),
161
                        ]
162
                    )
163
                )
164
            )
165
        );
166
    }
167
168
    /**
169
     * Return the view link.
170
     *
171
     * @return string
172
     */
173
    public function viewLink()
174
    {
175
        return app('html')->link($this->viewUrl(), $this->object->{$this->object->getTitleName()});
176
    }
177
178
    /**
179
     * When accessing a property of a decorated entry
180
     * object first check to see if the key represents
181
     * a streams field. If it does then return the field
182
     * type's presenter object. Otherwise handle normally.
183
     *
184
     * @param  $key
185
     * @return mixed
186
     */
187
    public function __get($key)
188
    {
189
        if ($assignment = $this->object->getAssignment($key)) {
0 ignored issues
show
The method getAssignment does only exist in Anomaly\Streams\Platform...Contract\EntryInterface, but not in Anomaly\Streams\Platform\Model\EloquentModel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
190
            $type = $assignment->getFieldType();
191
192
            if ($assignment->isTranslatable() && $locale = config('app.locale')) {
193
                $entry = $this->object->translateOrDefault($locale);
0 ignored issues
show
The method translateOrDefault does only exist in Anomaly\Streams\Platform\Model\EloquentModel, but not in Anomaly\Streams\Platform...Contract\EntryInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
194
195
                $type->setLocale($locale);
196
            } else {
197
                $entry = $this->object;
198
            }
199
200
            $type->setEntry($entry);
201
202
            if (method_exists($type, 'getRelation')) {
203
                return $type->decorate($entry->getRelationValue(camel_case($key)));
204
            }
205
206
            $type->setValue($entry->getFieldValue($key));
207
208
            return $type->getPresenter();
209
        }
210
211
        return $this->__getDecorator()->decorate(parent::__get($key));
212
    }
213
}
214