Sluggable::setSlug()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Larafolio\Helpers;
4
5
trait Sluggable
6
{
7
    /**
8
     * Set a snake_cased slug on model from model property.
9
     *
10
     * @param string $property Object property to make slug from.
11
     */
12
    protected function setSlug($property)
13
    {
14
        $slug = str_replace(' ', '_', $this->{$property});
15
16
        $this->slug = strtolower($slug);
1 ignored issue
show
Bug introduced by
The property slug 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...
17
    }
18
}
19