Passed
Push — master ( b539a7...1dc6a2 )
by John
03:54
created

convertMarkdownToHtml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 3
rs 10
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
use GrahamCampbell\Markdown\Facades\Markdown;
27
28
29
if (!function_exists('version')) {
30
    function version()
31
    {
32
        $version=new Version(
33
            '0.0.0',
34
            base_path()
35
        );
36
        return $version->getVersion();
37
    }
38
}
39
40
if (!function_exists('getCustomUrl')) {
41
    function getCustomUrl()
42
    {
43
        $customUrlCached=Cache::tags(['custom'])->get('url');
44
45
        if ($customUrlCached==null) {
46
            $urls=DB::table("custom_url")->where(["available"=>1])->get()->all();
47
            Cache::tags(['custom'])->put('url', $urls, 1200);
48
            return $urls;
49
        }
50
51
        return $customUrlCached;
52
    }
53
}
54
55
if (!function_exists('emailVerified')) {
56
    function emailVerified()
57
    {
58
        if (Auth::check()) {
59
            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...
60
        }
61
62
        return null;
63
    }
64
}
65
66
if (! function_exists('babel_path')) {
67
    /**
68
     * Get the path to the application folder.
69
     *
70
     * @param  string  $path
71
     * @return string
72
     */
73
    function babel_path($path = '')
74
    {
75
        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

75
        return /** @scrutinizer ignore-type */ app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path);
Loading history...
76
    }
77
}
78
79
if (! function_exists('glob_recursive')) {
80
    /**
81
     * Find pathnames matching a pattern recursively.
82
     *
83
     * @param  string  $pattern The pattern. No tilde expansion or parameter substitution is done.
84
     * @param  int     $flags   Valid flags: GLOB_MARK
85
     * @return array|false      an array containing the matched files/directories, an empty array if no file matched or false on error.
86
     */
87
    function glob_recursive($pattern, $flags = 0)
88
    {
89
        $files = glob($pattern, $flags);
90
        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
91
            $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

91
            $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

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