Passed
Branch dev (32180c)
by John
03:42
created

delFile()   B

Complexity

Conditions 9
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 9
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 15
rs 8.0555
1
<?php
2
3
use Illuminate\Support\Str;
4
use Illuminate\Support\Carbon;
5
use Illuminate\Support\HtmlString;
6
use Illuminate\Container\Container;
7
use Illuminate\Queue\CallQueuedClosure;
8
use Illuminate\Contracts\Bus\Dispatcher;
9
use Illuminate\Queue\SerializableClosure;
10
use Illuminate\Contracts\Auth\Access\Gate;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Gate. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use Illuminate\Contracts\Support\Responsable;
12
use Illuminate\Contracts\Routing\UrlGenerator;
13
use Illuminate\Foundation\Bus\PendingDispatch;
14
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Response. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use Illuminate\Contracts\Debug\ExceptionHandler;
16
use Illuminate\Contracts\Routing\ResponseFactory;
17
use Illuminate\Contracts\Auth\Factory as AuthFactory;
18
use Illuminate\Contracts\View\Factory as ViewFactory;
19
use Illuminate\Http\Exceptions\HttpResponseException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HttpResponseException. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
21
use Symfony\Component\Debug\Exception\FatalThrowableError;
22
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
23
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
24
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
25
use Illuminate\Support\Facades\DB;
26
27
if (!function_exists('version')) {
28
    function version()
29
    {
30
        $version=new Version(
31
            '0.0.0',
32
            base_path()
33
        );
34
        return $version->getVersion();
35
    }
36
}
37
38
if (!function_exists('getCustomUrl')) {
39
    function getCustomUrl()
40
    {
41
        $customUrlCached=Cache::tags(['custom'])->get('url');
42
43
        if ($customUrlCached==null) {
44
            $urls=DB::table("custom_url")->where(["available"=>1])->get()->all();
45
            Cache::tags(['custom'])->put('url', $urls, 1200);
46
            return $urls;
47
        }
48
49
        return $customUrlCached;
50
    }
51
}
52
53
if (!function_exists('emailVerified')) {
54
    function emailVerified()
55
    {
56
        if(Auth::check()){
57
            return !is_null(Auth::user()->email_verified_at);
0 ignored issues
show
Bug Best Practice introduced by
The property email_verified_at does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
        }
59
60
        return null;
61
    }
62
}
63
64
if (! function_exists('babel_path')) {
65
    /**
66
     * Get the path to the application folder.
67
     *
68
     * @param  string  $path
69
     * @return string
70
     */
71
    function babel_path($path = '')
72
    {
73
        return app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path);
0 ignored issues
show
Bug introduced by
Are you sure app('path') of type Illuminate\Contracts\Foundation\Application|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        return /** @scrutinizer ignore-type */ app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path);
Loading history...
74
    }
75
}
76
77
if (! function_exists('glob_recursive')) {
78
    /**
79
     * Find pathnames matching a pattern recursively.
80
     *
81
     * @param  string  $pattern The pattern. No tilde expansion or parameter substitution is done.
82
     * @param  int     $flags   Valid flags: GLOB_MARK
83
     * @return array|false      an array containing the matched files/directories, an empty array if no file matched or false on error.
84
     */
85
    function glob_recursive($pattern, $flags = 0)
86
    {
87
        $files = glob($pattern, $flags);
88
        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
89
            $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
0 ignored issues
show
Bug introduced by
It seems like $files can also be of type false; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
            $files = array_merge(/** @scrutinizer ignore-type */ $files, glob_recursive($dir.'/'.basename($pattern), $flags));
Loading history...
Bug introduced by
It seems like glob_recursive($dir . '/...name($pattern), $flags) can also be of type false; however, parameter $array2 of array_merge() does only seem to accept array|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
            $files = array_merge($files, /** @scrutinizer ignore-type */ glob_recursive($dir.'/'.basename($pattern), $flags));
Loading history...
90
        }
91
        return $files;
92
    }
93
}
94
95
if (!function_exists('adminMenu')) {
96
    function adminMenu()
97
    {
98
        return json_decode(file_get_contents(app_path('Admin/menu.json')),true);
99
    }
100
}
101
102
if (!function_exists('getOpenSearchXML')) {
103
    function getOpenSearchXML()
104
    {
105
        $url=config("app.url");
106
107
        return '<?xml version="1.0" encoding="UTF-8"?>
108
        <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
109
            <ShortName>NOJ</ShortName>
110
            <Description>Gracefully Search NOJ Problems and others.</Description>
111
            <InputEncoding>UTF-8</InputEncoding>
112
            <Image width="16" height="16" type="image/x-icon">'.$url.'/favicon.ico</Image>
113
            <Url type="text/html" method="get" template="'.$url.'/search/?q={searchTerms}&amp;tab=problems&amp;opensearch=1" />
114
            <moz:SearchForm>'.$url.'/search</moz:SearchForm>
115
        </OpenSearchDescription>';
116
    }
117
}
118
119
if (!function_exists('delFile')) {
120
    function delFile($dirName)
121
    {
122
        if (file_exists($dirName) && $handle=opendir($dirName)) {
123
            while (false!==($item = readdir($handle))) {
124
                if ($item!= "." && $item != "..") {
125
                    if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) {
126
                        delFile($dirName.'/'.$item);
127
                    } else {
128
                        if (unlink($dirName.'/'.$item)) {
129
                            return true;
130
                        }
131
                    }
132
                }
133
            }
134
            closedir($handle);
135
        }
136
    }
137
}
138