GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5119fb...242f35 )
by Andrea
02:50
created

Sluggable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B createSlug() 0 23 4
A getRelatedSlugs() 0 4 1
1
<?php
2
namespace Afrittella\BackProject\Traits;
3
4
trait Sluggable
5
{
6
    /**
7
     * Create a unique slug
8
     * @param $value
9
     * @param $id
10
     * @return string
11
     */
12
    public function createSlug($value, $id = 0)
13
    {
14
        $slug = str_slug($value);
15
16
        $relatedSlugs = $this->getRelatedSlugs($slug, $id);
17
18
        if (!$relatedSlugs->contains('slug', $slug)) {
19
            return $slug;
20
        }
21
22
        $completed = false;
23
        $i = 1;
24
25
        while ($completed == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
26
            $newSlug = $slug .'-'.$i;
27
            if (!$relatedSlugs->contains('slug', $newSlug)) {
28
                return $newSlug;
29
            }
30
            $i++;
31
        }
32
33
        return $slug;
34
    }
35
36
    /**
37
     * Get similar slugs
38
     * @param $slug
39
     * @param $id
40
     * @return mixed
41
     */
42
    protected function getRelatedSlugs($slug, $id = 0)
43
    {
44
        return $this->select('slug')->where('slug', 'like', $slug.'%')->where('id', '<>', $id)->get();
0 ignored issues
show
Bug introduced by
It seems like select() 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...
45
    }
46
}