CanPublish   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMigrationFileName() 0 10 1
1
<?php
2
3
namespace Angecode\LaravelFullName\Traits;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Filesystem\Filesystem;
7
8
/**
9
 * Trait CanPublish.
10
 *
11
 * @property $app
12
 *
13
 * @@codeCoverageIgnore
14
 */
15
trait CanPublish
16
{
17
    /**
18
     * Returns existing migration file if found, else uses the current timestamp.
19
     *
20
     * @param Filesystem $filesystem
21
     * @return string
22
     */
23
    protected function getMigrationFileName(Filesystem $filesystem): string
24
    {
25
        $timestamp = date('Y_m_d_His');
26
27
        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
0 ignored issues
show
Bug introduced by
The property app 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...
28
            ->flatMap(function ($path) use ($filesystem) {
29
                return $filesystem->glob($path.'*_add_fullname_to_users_table.php');
30
            })->push($this->app->databasePath()."/migrations/{$timestamp}_add_fullname_to_users_table.php")
31
            ->first();
32
    }
33
}
34