WaitsForSite   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 32
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A waitForSiteByName() 8 8 2
A waitForSite() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Class WaitsForSite.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait WaitsForSite
11
{
12
    use ItFetchesSites, Retries;
13
14
    /**
15
     * Wait for site to be available by name!
16
     *
17
     * @return mixed
18
     */
19 View Code Duplication
    protected function waitForSiteByName($site_name)
0 ignored issues
show
Duplication introduced by
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...
20
    {
21
        return $this->retry(50, function () use ($site_name) {
22
            $this->sites = $this->fetchSites(fp_env('ACACHA_FORGE_SERVER'));
0 ignored issues
show
Bug introduced by
The property sites 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...
23
            $site = $this->getSiteByName($this->sites, $site_name);
24
            return $site ? $site : null;
25
        });
26
    }
27
28
    /**
29
     * Wait for site to be installed!
30
     *
31
     * @return mixed
32
     */
33 View Code Duplication
    protected function waitForSite($site_id)
0 ignored issues
show
Duplication introduced by
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...
34
    {
35
        return $this->retry(50, function () use ($site_id) {
36
            $this->sites = $this->fetchSites(fp_env('ACACHA_FORGE_SERVER'));
37
            $site = $this->getSite($this->sites, $site_id);
38
            return $site->status == 'installed' ? $site : null;
39
        });
40
    }
41
}
42