Test Setup Failed
Push — master ( e40a57...f3143d )
by Phan
06:47 queued 01:08
created

app/Application.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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 App;
4
5
use Cache;
6
use Exception;
7
use GuzzleHttp\Client;
8
use Illuminate\Foundation\Application as IlluminateApplication;
9
use InvalidArgumentException;
10
use Log;
11
12
/**
13
 * Extends \Illuminate\Foundation\Application to override some defaults.
14
 */
15
class Application extends IlluminateApplication
16
{
17
    /**
18
     * Current Koel version. Must start with a v, and is synced with git tags/releases.
19
     *
20
     * @link https://github.com/phanan/koel/releases
21
     */
22
    const KOEL_VERSION = 'v3.6.2';
23
24
    /**
25
     * We have merged public path and base path.
26
     *
27
     * @return string
28
     */
29
    public function publicPath()
30
    {
31
        return $this->basePath;
32
    }
33
34
    /**
35
     * Loads a revision'ed asset file, making use of gulp-rev
36
     * This is a copycat of L5's Elixir, but catered to our directory structure.
37
     *
38
     * @param string $file
39
     * @param string $manifestFile
40
     *
41
     * @throws \InvalidArgumentException
42
     *
43
     * @return string
44
     */
45
    public function rev($file, $manifestFile = null)
46
    {
47
        static $manifest = null;
48
49
        $manifestFile = $manifestFile ?: public_path('public/mix-manifest.json');
50
51
        if ($manifest === null) {
52
            $manifest = json_decode(file_get_contents($manifestFile), true);
53
        }
54
55
        if (isset($manifest[$file])) {
56
            return file_exists(public_path('public/hot'))
57
                    ? "http://localhost:8080{$manifest[$file]}"
58
                    : $this->staticUrl("public{$manifest[$file]}");
59
        }
60
61
        throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
62
    }
63
64
    /**
65
     * Get a URL for static file requests.
66
     * If this installation of Koel has a CDN_URL configured, use it as the base.
67
     * Otherwise, just use a full URL to the asset.
68
     *
69
     * @param string $name The additional resource name/path.
70
     *
71
     * @return string
72
     */
73
    public function staticUrl($name = null)
74
    {
75
        $cdnUrl = trim(config('koel.cdn.url'), '/ ');
76
77
        return $cdnUrl ? $cdnUrl.'/'.trim(ltrim($name, '/')) : trim(asset($name));
78
    }
79
80
    /**
81
     * Get the latest version number of Koel from GitHub.
82
     *
83
     * @param Client $client
84
     *
85
     * @return string
86
     */
87
    public function getLatestVersion(Client $client = null)
88
    {
89
        return Cache::remember('latestKoelVersion', 1 * 24 * 60, function () use ($client) {
90
            $client = $client ?: new Client();
0 ignored issues
show
Consider using a different name than the imported variable $client, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
91
92
            try {
93
                $v = json_decode(
94
                    $client->get('https://api.github.com/repos/phanan/koel/tags')
95
                        ->getBody()
96
                )[0]->name;
97
98
                return $v;
99
            } catch (Exception $e) {
100
                Log::error($e);
101
102
                return self::KOEL_VERSION;
103
            }
104
        });
105
    }
106
}
107