Issues (13)

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/Publishable.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
2
3
namespace Bmatovu\Publishable;
4
5
/**
6
 * @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withDrafts()
7
 * @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyDrafts()
8
 * @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyPublished()
9
 */
10
trait Publishable
11
{
12
    /**
13
     * Boot the has-drafts trait for a model.
14
     *
15
     * @return void
16
     */
17 3
    public static function bootPublishable()
18
    {
19 3
        static::addGlobalScope(new PublishedScope);
20 3
    }
21
22
    /**
23
     * Initialize this trait for an instance.
24
     *
25
     * @return void
26
     */
27 3
    public function initializePublishable()
28
    {
29 3
        $this->dates[] = $this->getPublishedAtColumn();
0 ignored issues
show
The property dates does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30 3
    }
31
32
    /**
33
     * Save instance of this model as published.
34
     *
35
     * @param array $options
36
     *
37
     * @return bool
38
     */
39 1 View Code Duplication
    public function publish(array $options = [])
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...
40
    {
41
        // https://laravel-news.com/laravel-model-events-getting-started
42
        // https://gist.github.com/scrubmx/7fc20663ce2b3ac103a2879915b572be
43
        // https://www.google.com/search?q=laravel+register+fire+model+event&oq=laravel+register+fire+model+event
44
45
        // If the "publishing" event returns false we bail out immediately and return false,
46
        // indicating that the save failed. This provides a chance for any
47
        // listeners to cancel save operations if validations fail or whatever.
48 1
        if ($this->fireModelEvent('publishing') === false) {
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
            return false;
50
        }
51
52 1
        $this->{$this->getPublishedAtColumn()} = $this->freshTimestamp();
0 ignored issues
show
It seems like freshTimestamp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
53
54 1
        $saved = parent::save($options);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (save() instead of publish()). Are you sure this is correct? If so, you might want to change this to $this->save().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
55
56 1
        if ($saved) {
57 1
            $this->fireModelEvent('published', false);
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
        }
59
60 1
        return $saved;
61
    }
62
63
    /**
64
     * Toogle model instance state to non-published.
65
     *
66
     * @param array $options
67
     *
68
     * @return bool
69
     */
70 1 View Code Duplication
    public function unpublish(array $options = [])
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...
71
    {
72 1
        if ($this->fireModelEvent('unpublishing') === false) {
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
73
            return false;
74
        }
75
76 1
        $this->{$this->getPublishedAtColumn()} = null;
77
78 1
        $saved = parent::save($options);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (save() instead of unpublish()). Are you sure this is correct? If so, you might want to change this to $this->save().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
79
80 1
        if ($saved) {
81 1
            $this->fireModelEvent('unpublished', false);
0 ignored issues
show
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
82
        }
83
84 1
        return $saved;
85
    }
86
87
    /**
88
     * Save instance of this model as a draft.
89
     *
90
     * @param array $options
91
     *
92
     * @return bool
93
     */
94
    public function draft(array $options = [])
95
    {
96
        return $this->unpublish($options);
97
    }
98
99
    /**
100
     * Register a "publishing" model event callback with the dispatcher.
101
     *
102
     * @param \Closure|string $callback
103
     *
104
     * @return void
105
     */
106
    public static function publishing($callback)
107
    {
108
        static::registerModelEvent('publishing', $callback);
109
    }
110
111
    /**
112
     * Register a "published" model event callback with the dispatcher.
113
     *
114
     * @param \Closure|string $callback
115
     *
116
     * @return void
117
     */
118
    public static function published($callback)
119
    {
120
        static::registerModelEvent('published', $callback);
121
    }
122
123
    /**
124
     * Register a "unpublishing" model event callback with the dispatcher.
125
     *
126
     * @param \Closure|string $callback
127
     *
128
     * @return void
129
     */
130
    public static function unpublishing($callback)
131
    {
132
        static::registerModelEvent('unpublishing', $callback);
133
    }
134
135
    /**
136
     * Register a "unpublished" model event callback with the dispatcher.
137
     *
138
     * @param \Closure|string $callback
139
     *
140
     * @return void
141
     */
142
    public static function unpublished($callback)
143
    {
144
        static::registerModelEvent('unpublished', $callback);
145
    }
146
147
    /**
148
     * Determine if the model instance is published.
149
     *
150
     * @return bool
151
     */
152 1
    public function isPublished()
153
    {
154 1
        return ! is_null($this->{$this->getPublishedAtColumn()});
155
    }
156
157
    /**
158
     * Get the name of the "published at" column.
159
     *
160
     * @return string
161
     */
162 3
    public function getPublishedAtColumn()
163
    {
164 3
        return defined('static::PUBLISHED_AT') ? static::PUBLISHED_AT : 'published_at';
165
    }
166
167
    /**
168
     * Get the fully qualified "published at" column.
169
     *
170
     * @return string
171
     */
172 1
    public function getQualifiedPublishedAtColumn()
173
    {
174 1
        return $this->qualifyColumn($this->getPublishedAtColumn());
0 ignored issues
show
It seems like qualifyColumn() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
175
    }
176
}
177