mtvbrianking /
laravel-publishable
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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(); |
|
| 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 = []) |
| 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) { |
|
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | 1 | $this->{$this->getPublishedAtColumn()} = $this->freshTimestamp(); |
|
| 53 | |||
| 54 | 1 | $saved = parent::save($options); |
|
|
0 ignored issues
–
show
|
|||
| 55 | |||
| 56 | 1 | if ($saved) { |
|
| 57 | 1 | $this->fireModelEvent('published', false); |
|
| 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 = []) |
| 71 | { |
||
| 72 | 1 | if ($this->fireModelEvent('unpublishing') === false) { |
|
| 73 | return false; |
||
| 74 | } |
||
| 75 | |||
| 76 | 1 | $this->{$this->getPublishedAtColumn()} = null; |
|
| 77 | |||
| 78 | 1 | $saved = parent::save($options); |
|
|
0 ignored issues
–
show
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 Loading history...
|
|||
| 79 | |||
| 80 | 1 | if ($saved) { |
|
| 81 | 1 | $this->fireModelEvent('unpublished', false); |
|
| 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()); |
|
| 175 | } |
||
| 176 | } |
||
| 177 |
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:
The
getFirstName()method in theSoncalls the wrong method in the parent class.