@@ -53,8 +53,9 @@ |
||
| 53 | 53 | |
| 54 | 54 | private function getDriverInstance () |
| 55 | 55 | {
|
| 56 | - if (!$this->driver_instance) |
|
| 57 | - $this->setDriverInstance(); |
|
| 56 | + if (!$this->driver_instance) {
|
|
| 57 | + $this->setDriverInstance(); |
|
| 58 | + } |
|
| 58 | 59 | |
| 59 | 60 | return $this->driver_instance; |
| 60 | 61 | } |
@@ -46,8 +46,9 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | // Check if given url has been shorten previously |
| 48 | 48 | $duplicate = Link::where(['long_path' => $this->path])->first(); |
| 49 | - if ($duplicate) |
|
| 50 | - return $duplicate->base_url . "/" . $duplicate->short_path; |
|
| 49 | + if ($duplicate) {
|
|
| 50 | + return $duplicate->base_url . "/" . $duplicate->short_path; |
|
| 51 | + } |
|
| 51 | 52 | |
| 52 | 53 | $short_path = $this->getNextShortpath(); |
| 53 | 54 | |
@@ -77,8 +78,9 @@ discard block |
||
| 77 | 78 | {
|
| 78 | 79 | $min_length = $this->config['min_length']; |
| 79 | 80 | $short_path = ""; |
| 80 | - for ($i = 0; $i < $min_length; $i++) |
|
| 81 | - $short_path .= $this->head; |
|
| 81 | + for ($i = 0; $i < $min_length; $i++) {
|
|
| 82 | + $short_path .= $this->head; |
|
| 83 | + } |
|
| 82 | 84 | return $short_path; |
| 83 | 85 | } |
| 84 | 86 | |
@@ -91,8 +93,9 @@ discard block |
||
| 91 | 93 | */ |
| 92 | 94 | private function findNextPerm (string $current_perm) :string |
| 93 | 95 | {
|
| 94 | - if (!strlen($current_perm)) |
|
| 95 | - return $this->head; |
|
| 96 | + if (!strlen($current_perm)) {
|
|
| 97 | + return $this->head; |
|
| 98 | + } |
|
| 96 | 99 | |
| 97 | 100 | $arr = array_reverse(str_split($current_perm)); |
| 98 | 101 | foreach($arr as $key => $current_char) {
|
@@ -120,12 +123,15 @@ discard block |
||
| 120 | 123 | {
|
| 121 | 124 | $parse = parse_url($url); |
| 122 | 125 | $path = ""; |
| 123 | - if ($parse['path'] ?? null) |
|
| 124 | - $path .= str::replaceFirst("/", "", $parse['path']);
|
|
| 125 | - if ($parse['query'] ?? null) |
|
| 126 | - $path .= "?" . $parse['query']; |
|
| 127 | - if ($parse['fragment'] ?? null) |
|
| 128 | - $path .= "#" . $parse['fragment']; |
|
| 126 | + if ($parse['path'] ?? null) {
|
|
| 127 | + $path .= str::replaceFirst("/", "", $parse['path']);
|
|
| 128 | + } |
|
| 129 | + if ($parse['query'] ?? null) {
|
|
| 130 | + $path .= "?" . $parse['query']; |
|
| 131 | + } |
|
| 132 | + if ($parse['fragment'] ?? null) {
|
|
| 133 | + $path .= "#" . $parse['fragment']; |
|
| 134 | + } |
|
| 129 | 135 | |
| 130 | 136 | $this->base_url = str_replace("/" . $path, "", $url);
|
| 131 | 137 | $this->path = $path; |
@@ -151,20 +157,21 @@ discard block |
||
| 151 | 157 | // so we must find the latest one(short_path) in the permutation of the main_str |
| 152 | 158 | $latest = collect(\DB::select("SELECT short_path FROM $tbl WHERE created_at = (SELECT MAX(created_at) FROM $tbl)"));
|
| 153 | 159 | |
| 154 | - if (!$latest->count()) |
|
| 155 | - return $this->getFirstUrl(); |
|
| 160 | + if (!$latest->count()) {
|
|
| 161 | + return $this->getFirstUrl(); |
|
| 162 | + } |
|
| 156 | 163 | |
| 157 | 164 | if ($latest->count() == 1) {
|
| 158 | 165 | return $this->findNextPerm($latest->first()->short_path); |
| 159 | - } |
|
| 160 | - else {
|
|
| 166 | + } else {
|
|
| 161 | 167 | foreach ($latest->reverse() as $key => $item) {
|
| 162 | 168 | $next = $this->findNextPerm($item->short_path); |
| 163 | 169 | |
| 164 | 170 | // If next permutation of current item is in fetched items |
| 165 | 171 | // find next permutation of the next fetched one |
| 166 | - if (!$latest->contains("short_path", $next))
|
|
| 167 | - return $next; |
|
| 172 | + if (!$latest->contains("short_path", $next)) {
|
|
| 173 | + return $next; |
|
| 174 | + } |
|
| 168 | 175 | } |
| 169 | 176 | } |
| 170 | 177 | } |