@@ -68,7 +68,9 @@ |
||
| 68 | 68 | |
| 69 | 69 | foreach ($schemas as $schema) { |
| 70 | 70 | $schema = $schema['Create Table']; |
| 71 | - if ($this->removeAI) $schema = preg_replace('/AUTO_INCREMENT=([0-9]+)(\s{0,1})/', '', $schema); |
|
| 71 | + if ($this->removeAI) { |
|
| 72 | + $schema = preg_replace('/AUTO_INCREMENT=([0-9]+)(\s{0,1})/', '', $schema); |
|
| 73 | + } |
|
| 72 | 74 | $this->ln($schema . ";\n\n"); |
| 73 | 75 | } |
| 74 | 76 | } |
@@ -1024,19 +1024,19 @@ discard block |
||
| 1024 | 1024 | |
| 1025 | 1025 | $value = $this->format($value); |
| 1026 | 1026 | |
| 1027 | - if ( null === $value ) { |
|
| 1027 | + if (null === $value) { |
|
| 1028 | 1028 | |
| 1029 | 1029 | return "NULL"; |
| 1030 | 1030 | |
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | - if ( false === $value ) { |
|
| 1033 | + if (false === $value) { |
|
| 1034 | 1034 | |
| 1035 | 1035 | return "'0'"; |
| 1036 | 1036 | |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - if ( true === $value ) { |
|
| 1039 | + if (true === $value) { |
|
| 1040 | 1040 | |
| 1041 | 1041 | return "'1'"; |
| 1042 | 1042 | |
@@ -1099,7 +1099,7 @@ discard block |
||
| 1099 | 1099 | $identifier = explode(".", $identifier); |
| 1100 | 1100 | |
| 1101 | 1101 | $identifier = array_map( |
| 1102 | - function ($part) use ($delimiter) { |
|
| 1102 | + function($part) use ($delimiter) { |
|
| 1103 | 1103 | return $delimiter . str_replace($delimiter, $delimiter . $delimiter, $part) . $delimiter; |
| 1104 | 1104 | }, |
| 1105 | 1105 | $identifier |
@@ -437,7 +437,9 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | $primary = $this->getPrimary($table); |
| 439 | 439 | |
| 440 | - if (is_array($primary)) return null; |
|
| 440 | + if (is_array($primary)) { |
|
| 441 | + return null; |
|
| 442 | + } |
|
| 441 | 443 | |
| 442 | 444 | $table = $this->rewriteTable($table); |
| 443 | 445 | |
@@ -608,8 +610,12 @@ discard block |
||
| 608 | 610 | function insert($table, $rows, $method = null) |
| 609 | 611 | { |
| 610 | 612 | |
| 611 | - if (empty($rows)) return; |
|
| 612 | - if (!isset($rows[0])) $rows = array($rows); |
|
| 613 | + if (empty($rows)) { |
|
| 614 | + return; |
|
| 615 | + } |
|
| 616 | + if (!isset($rows[0])) { |
|
| 617 | + $rows = array($rows); |
|
| 618 | + } |
|
| 613 | 619 | |
| 614 | 620 | if ($method === 'prepared') { |
| 615 | 621 | |
@@ -638,7 +644,9 @@ discard block |
||
| 638 | 644 | { |
| 639 | 645 | |
| 640 | 646 | $columns = $this->getColumns($rows); |
| 641 | - if (empty($columns)) return; |
|
| 647 | + if (empty($columns)) { |
|
| 648 | + return; |
|
| 649 | + } |
|
| 642 | 650 | |
| 643 | 651 | $query = $this->insertHead($table, $columns); |
| 644 | 652 | $query .= "( ?" . str_repeat(", ?", count($columns) - 1) . " )"; |
@@ -677,7 +685,9 @@ discard block |
||
| 677 | 685 | { |
| 678 | 686 | |
| 679 | 687 | $columns = $this->getColumns($rows); |
| 680 | - if (empty($columns)) return; |
|
| 688 | + if (empty($columns)) { |
|
| 689 | + return; |
|
| 690 | + } |
|
| 681 | 691 | |
| 682 | 692 | $query = $this->insertHead($table, $columns); |
| 683 | 693 | $lists = $this->valueLists($rows, $columns); |
@@ -703,7 +713,9 @@ discard block |
||
| 703 | 713 | { |
| 704 | 714 | |
| 705 | 715 | $columns = $this->getColumns($rows); |
| 706 | - if (empty($columns)) return; |
|
| 716 | + if (empty($columns)) { |
|
| 717 | + return; |
|
| 718 | + } |
|
| 707 | 719 | |
| 708 | 720 | $query = $this->insertHead($table, $columns); |
| 709 | 721 | $lists = $this->valueLists($rows, $columns); |
@@ -811,7 +823,9 @@ discard block |
||
| 811 | 823 | function update($table, $data, $where = array(), $params = array()) |
| 812 | 824 | { |
| 813 | 825 | |
| 814 | - if (empty($data)) return; |
|
| 826 | + if (empty($data)) { |
|
| 827 | + return; |
|
| 828 | + } |
|
| 815 | 829 | |
| 816 | 830 | $set = array(); |
| 817 | 831 | |
@@ -821,8 +835,12 @@ discard block |
||
| 821 | 835 | |
| 822 | 836 | } |
| 823 | 837 | |
| 824 | - if (!is_array($where)) $where = array($where); |
|
| 825 | - if (!is_array($params)) $params = array_slice(func_get_args(), 3); |
|
| 838 | + if (!is_array($where)) { |
|
| 839 | + $where = array($where); |
|
| 840 | + } |
|
| 841 | + if (!is_array($params)) { |
|
| 842 | + $params = array_slice(func_get_args(), 3); |
|
| 843 | + } |
|
| 826 | 844 | |
| 827 | 845 | $table = $this->rewriteTable($table); |
| 828 | 846 | $query = "UPDATE " . $this->quoteIdentifier($table); |
@@ -851,8 +869,12 @@ discard block |
||
| 851 | 869 | function delete($table, $where = array(), $params = array()) |
| 852 | 870 | { |
| 853 | 871 | |
| 854 | - if (!is_array($where)) $where = array($where); |
|
| 855 | - if (!is_array($params)) $params = array_slice(func_get_args(), 2); |
|
| 872 | + if (!is_array($where)) { |
|
| 873 | + $where = array($where); |
|
| 874 | + } |
|
| 875 | + if (!is_array($params)) { |
|
| 876 | + $params = array_slice(func_get_args(), 2); |
|
| 877 | + } |
|
| 856 | 878 | |
| 857 | 879 | $table = $this->rewriteTable($table); |
| 858 | 880 | $query = "DELETE FROM " . $this->quoteIdentifier($table); |
@@ -1094,7 +1116,9 @@ discard block |
||
| 1094 | 1116 | |
| 1095 | 1117 | $delimiter = $this->identifierDelimiter; |
| 1096 | 1118 | |
| 1097 | - if (empty($delimiter)) return $identifier; |
|
| 1119 | + if (empty($delimiter)) { |
|
| 1120 | + return $identifier; |
|
| 1121 | + } |
|
| 1098 | 1122 | |
| 1099 | 1123 | $identifier = explode(".", $identifier); |
| 1100 | 1124 | |
@@ -111,7 +111,9 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | if ($where !== null) { |
| 113 | 113 | |
| 114 | - if (!is_array($params)) $params = array_slice(func_get_args(), 2); |
|
| 114 | + if (!is_array($params)) { |
|
| 115 | + $params = array_slice(func_get_args(), 2); |
|
| 116 | + } |
|
| 115 | 117 | $result = $result->where($where, $params); |
| 116 | 118 | |
| 117 | 119 | } |
@@ -129,7 +131,9 @@ discard block |
||
| 129 | 131 | function via($key) |
| 130 | 132 | { |
| 131 | 133 | |
| 132 | - if (!$this->parent_) throw new \LogicException('Cannot set reference key on basic Result'); |
|
| 134 | + if (!$this->parent_) { |
|
| 135 | + throw new \LogicException('Cannot set reference key on basic Result'); |
|
| 136 | + } |
|
| 133 | 137 | |
| 134 | 138 | $clone = clone $this; |
| 135 | 139 | |
@@ -155,7 +159,9 @@ discard block |
||
| 155 | 159 | function execute() |
| 156 | 160 | { |
| 157 | 161 | |
| 158 | - if (isset($this->rows)) return $this; |
|
| 162 | + if (isset($this->rows)) { |
|
| 163 | + return $this; |
|
| 164 | + } |
|
| 159 | 165 | |
| 160 | 166 | if ($this->parent_) { |
| 161 | 167 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | 'separator' => ',', |
| 147 | 147 | ], |
| 148 | 148 | ]; |
| 149 | - foreach($clausules as $key => $clausule) { |
|
| 149 | + foreach ($clausules as $key => $clausule) { |
|
| 150 | 150 | if (isset($this->clausules[$key])) { |
| 151 | 151 | $value = $this->clausules[$key]; |
| 152 | 152 | if (is_array($value)) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | 'separator' => ' ', |
| 203 | 203 | ] |
| 204 | 204 | ]; |
| 205 | - foreach($clausules as $key => $clausule) { |
|
| 205 | + foreach ($clausules as $key => $clausule) { |
|
| 206 | 206 | if (isset($this->clausules[$key])) { |
| 207 | 207 | $value = $this->clausules[$key]; |
| 208 | 208 | if (is_array($value)) { |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | 'separator' => ' ', |
| 245 | 245 | ] |
| 246 | 246 | ]; |
| 247 | - foreach($clausules as $key => $clausule) { |
|
| 247 | + foreach ($clausules as $key => $clausule) { |
|
| 248 | 248 | if (isset($this->clausules[$key])) { |
| 249 | 249 | $value = $this->clausules[$key]; |
| 250 | 250 | if (is_array($value)) { |
@@ -97,7 +97,9 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | if (stripos($rows[1], '(')) { |
| 99 | 99 | $type[$table][] = stristr($rows[1], '(', true); |
| 100 | - } else $type[$table][] = $rows[1]; |
|
| 100 | + } else { |
|
| 101 | + $type[$table][] = $rows[1]; |
|
| 102 | + } |
|
| 101 | 103 | |
| 102 | 104 | $return .= $rows[0]; |
| 103 | 105 | $count++; |
@@ -125,7 +127,11 @@ discard block |
||
| 125 | 127 | |
| 126 | 128 | if (isset($row[$j])) { |
| 127 | 129 | //if number, take away "". else leave as string |
| 128 | - if (in_array($type[$table][$j], $numtypes)) $return .= $row[$j]; else $return .= '"' . $row[$j] . '"'; |
|
| 130 | + if (in_array($type[$table][$j], $numtypes)) { |
|
| 131 | + $return .= $row[$j]; |
|
| 132 | + } else { |
|
| 133 | + $return .= '"' . $row[$j] . '"'; |
|
| 134 | + } |
|
| 129 | 135 | } else { |
| 130 | 136 | $return .= '""'; |
| 131 | 137 | } |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | } |
| 130 | 130 | break; |
| 131 | 131 | case 'object': |
| 132 | - if ( false !== ($id = array_search($var, self::$_objects, true)) ) { |
|
| 132 | + if (false !== ($id = array_search($var, self::$_objects, true))) { |
|
| 133 | 133 | self::$_output .= get_class($var) . '#' . ($id + 1) . '(...)'; |
| 134 | 134 | } elseif (self::$_depth <= $level) { |
| 135 | 135 | self::$_output .= get_class($var) . '(...)'; |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | private static $tempo_da_sessao; |
| 27 | 27 | |
| 28 | - public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) |
|
| 29 | - { |
|
| 28 | + public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) |
|
| 29 | + { |
|
| 30 | 30 | $distanceInSeconds = round(abs($toTime - strtotime($fromTime))); |
| 31 | 31 | $distanceInMinutes = round($distanceInSeconds / 60); |
| 32 | 32 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $now = time(); |
| 128 | 128 | $unix_date = strtotime($date); |
| 129 | 129 | |
| 130 | - // check validity of date |
|
| 130 | + // check validity of date |
|
| 131 | 131 | if(empty($unix_date)) { |
| 132 | 132 | return "Bad date"; |
| 133 | 133 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public static function setDataTime($data, string $strftime='%d %B %Y', string $format = 'Y-m-d H:i:s') |
|
| 98 | + public static function setDataTime($data, string $strftime = '%d %B %Y', string $format = 'Y-m-d H:i:s') |
|
| 99 | 99 | { |
| 100 | 100 | $data = new \DateTime($data); |
| 101 | 101 | $data_f = $data->format($format); |
@@ -111,45 +111,45 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | public static function nicetime($date, array $translate = ["second", "minute", "hour", "day", "week", "month", "year", "decade"]) |
| 113 | 113 | { |
| 114 | - if(empty($date)) { |
|
| 114 | + if (empty($date)) { |
|
| 115 | 115 | return "No date provided"; |
| 116 | 116 | } |
| 117 | - if(!is_array($translate)) { |
|
| 117 | + if (!is_array($translate)) { |
|
| 118 | 118 | return "the expected value is not an array"; |
| 119 | 119 | } |
| 120 | - if( 5 > count($translate)){ |
|
| 120 | + if (5 > count($translate)) { |
|
| 121 | 121 | return "the matrix needs 5 to 8 values (second, minute, hour, day, week,month, year, decade)"; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $periods = $translate; |
| 125 | - $lengths = array("60","60","24","7","4.35","12","10"); |
|
| 125 | + $lengths = array("60", "60", "24", "7", "4.35", "12", "10"); |
|
| 126 | 126 | |
| 127 | 127 | $now = time(); |
| 128 | - $unix_date = strtotime($date); |
|
| 128 | + $unix_date = strtotime($date); |
|
| 129 | 129 | |
| 130 | 130 | // check validity of date |
| 131 | - if(empty($unix_date)) { |
|
| 131 | + if (empty($unix_date)) { |
|
| 132 | 132 | return "Bad date"; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // is it future date or past date |
| 136 | - if($now > $unix_date) { |
|
| 137 | - $difference = $now - $unix_date; |
|
| 138 | - $tense = "ago"; |
|
| 136 | + if ($now > $unix_date) { |
|
| 137 | + $difference = $now - $unix_date; |
|
| 138 | + $tense = "ago"; |
|
| 139 | 139 | |
| 140 | 140 | } else { |
| 141 | - $difference = $unix_date - $now; |
|
| 142 | - $tense = "from now"; |
|
| 141 | + $difference = $unix_date - $now; |
|
| 142 | + $tense = "from now"; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { |
|
| 145 | + for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) { |
|
| 146 | 146 | $difference /= $lengths[$j]; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $difference = round($difference); |
| 150 | 150 | |
| 151 | - if($difference != 1) { |
|
| 152 | - $periods[$j].= "s"; |
|
| 151 | + if ($difference != 1) { |
|
| 152 | + $periods[$j] .= "s"; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | return "$difference $periods[$j] {$tense}"; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | return $abbreviation; |
| 89 | 89 | } |
| 90 | - /* |
|
| 90 | + /* |
|
| 91 | 91 | * $string string |
| 92 | 92 | * example removeAccentsIstring( "Õ") output "O" |
| 93 | 93 | */ |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | public static function removeAccents($string, $slug = false) |
| 101 | 101 | { |
| 102 | 102 | $string = strtolower($string); |
| 103 | - // ASCII code of vowels |
|
| 103 | + // ASCII code of vowels |
|
| 104 | 104 | $ascii['a'] = range(224, 230); |
| 105 | 105 | $ascii['e'] = range(232, 235); |
| 106 | 106 | $ascii['i'] = range(236, 239); |
| 107 | 107 | $ascii['o'] = array_merge(range(242, 246), array(240, 248)); |
| 108 | 108 | $ascii['u'] = range(249, 252); |
| 109 | - // ASCII code for other characters |
|
| 109 | + // ASCII code for other characters |
|
| 110 | 110 | $ascii['b'] = array(223); |
| 111 | 111 | $ascii['c'] = array(231); |
| 112 | 112 | $ascii['d'] = array(208); |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | $string = preg_replace(array_values($troca), array_keys($troca), $string); |
| 121 | 121 | // Slug? |
| 122 | 122 | if ($slug) { |
| 123 | - // Swap anything that is not letter or number for a character ($slug) |
|
| 124 | - $string = preg_replace('/[^a-z0-9]/i', $slug, $string); |
|
| 125 | - // Removes repeated characters ($slug) |
|
| 126 | - $string = preg_replace('/' . $slug . '{2,}/i', $slug, $string); |
|
| 123 | + // Swap anything that is not letter or number for a character ($slug) |
|
| 124 | + $string = preg_replace('/[^a-z0-9]/i', $slug, $string); |
|
| 125 | + // Removes repeated characters ($slug) |
|
| 126 | + $string = preg_replace('/' . $slug . '{2,}/i', $slug, $string); |
|
| 127 | 127 | $string = trim($string, $slug); |
| 128 | 128 | } |
| 129 | 129 | return $string; |
@@ -48,42 +48,42 @@ |
||
| 48 | 48 | |
| 49 | 49 | public static function abbreviate($strString, $intLength = NULL) |
| 50 | 50 | { |
| 51 | - $defaultAbbrevLength = 8; //Default abbreviation length if none is specified |
|
| 51 | + $defaultAbbrevLength = 8; //Default abbreviation length if none is specified |
|
| 52 | 52 | |
| 53 | 53 | //Set up the string for processing |
| 54 | - $strString = preg_replace("/[^A-Za-z0-9]/", '', $strString); //Remove non-alphanumeric characters |
|
| 55 | - $strString = ucfirst($strString); //Capitalize the first character (helps with abbreviation calcs) |
|
| 54 | + $strString = preg_replace("/[^A-Za-z0-9]/", '', $strString); //Remove non-alphanumeric characters |
|
| 55 | + $strString = ucfirst($strString); //Capitalize the first character (helps with abbreviation calcs) |
|
| 56 | 56 | $stringIndex = 0; |
| 57 | 57 | //Figure out everything we need to know about the resulting abbreviation string |
| 58 | - $uppercaseCount = preg_match_all('/[A-Z]/', $strString, $uppercaseLetters, PREG_OFFSET_CAPTURE); //Record occurences of uppercase letters and their indecies in the $uppercaseLetters array, take note of how many there are |
|
| 59 | - $targetLength = isset($intLength) ? intval($intLength) : $defaultAbbrevLength; //Maximum length of the abbreviation |
|
| 60 | - $uppercaseCount = $uppercaseCount > $targetLength ? $targetLength : $uppercaseCount; //If there are more uppercase letters than the target length, adjust uppercaseCount to ignore overflow |
|
| 61 | - $targetWordLength = round($targetLength / intval($uppercaseCount)); //How many characters need to be taken from each uppercase-designated "word" in order to best meet the target length? |
|
| 62 | - $abbrevLength = 0; //How long the abbreviation currently is |
|
| 63 | - $abbreviation = ''; //The actual abbreviation |
|
| 58 | + $uppercaseCount = preg_match_all('/[A-Z]/', $strString, $uppercaseLetters, PREG_OFFSET_CAPTURE); //Record occurences of uppercase letters and their indecies in the $uppercaseLetters array, take note of how many there are |
|
| 59 | + $targetLength = isset($intLength) ? intval($intLength) : $defaultAbbrevLength; //Maximum length of the abbreviation |
|
| 60 | + $uppercaseCount = $uppercaseCount > $targetLength ? $targetLength : $uppercaseCount; //If there are more uppercase letters than the target length, adjust uppercaseCount to ignore overflow |
|
| 61 | + $targetWordLength = round($targetLength / intval($uppercaseCount)); //How many characters need to be taken from each uppercase-designated "word" in order to best meet the target length? |
|
| 62 | + $abbrevLength = 0; //How long the abbreviation currently is |
|
| 63 | + $abbreviation = ''; //The actual abbreviation |
|
| 64 | 64 | //Create respective arrays for the occurence indecies and the actual characters of uppercase characters within the string |
| 65 | 65 | for ($i = 0; $i < $uppercaseCount; $i++) { |
| 66 | 66 | //$ucIndicies[] = $uppercaseLetters[1]; //Not actually used. Could be used to calculate abbreviations more efficiently than the routine below by strictly considering indecies |
| 67 | 67 | $ucLetters[] = $uppercaseLetters[0][$i][0]; |
| 68 | 68 | } |
| 69 | - $characterDeficit = 0; //Gets incremented when an uppercase letter is encountered before $targetCharsPerWord characters have been collected since the last UC char. |
|
| 70 | - $wordIndex = $targetWordLength; //HACK: keeps track of how many characters have been carried into the abbreviation since the last UC char |
|
| 69 | + $characterDeficit = 0; //Gets incremented when an uppercase letter is encountered before $targetCharsPerWord characters have been collected since the last UC char. |
|
| 70 | + $wordIndex = $targetWordLength; //HACK: keeps track of how many characters have been carried into the abbreviation since the last UC char |
|
| 71 | 71 | while ($stringIndex < strlen($strString)) { //Process the whole input string... |
| 72 | 72 | if ($abbrevLength >= $targetLength) //...unless the abbreviation has hit the target length cap |
| 73 | 73 | break; |
| 74 | - $currentChar = $strString[$stringIndex++]; //Grab a character from the string, advance the string cursor |
|
| 74 | + $currentChar = $strString[$stringIndex++]; //Grab a character from the string, advance the string cursor |
|
| 75 | 75 | if (in_array($currentChar, $ucLetters)) { //If handling a UC char, consider it a new word |
| 76 | - $characterDeficit += $targetWordLength - $wordIndex; //If UC chars are closer together than targetWordLength, keeps track of how many extra characters are required to fit the target length of the abbreviation |
|
| 77 | - $wordIndex = 0; //Set the wordIndex to reflect a new word |
|
| 76 | + $characterDeficit += $targetWordLength - $wordIndex; //If UC chars are closer together than targetWordLength, keeps track of how many extra characters are required to fit the target length of the abbreviation |
|
| 77 | + $wordIndex = 0; //Set the wordIndex to reflect a new word |
|
| 78 | 78 | } else if ($wordIndex >= $targetWordLength) { |
| 79 | 79 | if ($characterDeficit == 0) //If the word is full and we're not short any characters, ignore the character |
| 80 | 80 | continue; |
| 81 | 81 | else |
| 82 | - $characterDefecit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 82 | + $characterDefecit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 83 | 83 | } |
| 84 | - $abbreviation .= $currentChar; //Add the character to the abbreviation |
|
| 85 | - $abbrevLength++; //Increment abbreviation length |
|
| 86 | - $wordIndex++; //Increment the number of characters for this word |
|
| 84 | + $abbreviation .= $currentChar; //Add the character to the abbreviation |
|
| 85 | + $abbrevLength++; //Increment abbreviation length |
|
| 86 | + $wordIndex++; //Increment the number of characters for this word |
|
| 87 | 87 | } |
| 88 | 88 | return $abbreviation; |
| 89 | 89 | } |
@@ -69,17 +69,22 @@ discard block |
||
| 69 | 69 | $characterDeficit = 0; //Gets incremented when an uppercase letter is encountered before $targetCharsPerWord characters have been collected since the last UC char. |
| 70 | 70 | $wordIndex = $targetWordLength; //HACK: keeps track of how many characters have been carried into the abbreviation since the last UC char |
| 71 | 71 | while ($stringIndex < strlen($strString)) { //Process the whole input string... |
| 72 | - if ($abbrevLength >= $targetLength) //...unless the abbreviation has hit the target length cap |
|
| 72 | + if ($abbrevLength >= $targetLength) { |
|
| 73 | + //...unless the abbreviation has hit the target length cap |
|
| 73 | 74 | break; |
| 75 | + } |
|
| 74 | 76 | $currentChar = $strString[$stringIndex++]; //Grab a character from the string, advance the string cursor |
| 75 | 77 | if (in_array($currentChar, $ucLetters)) { //If handling a UC char, consider it a new word |
| 76 | 78 | $characterDeficit += $targetWordLength - $wordIndex; //If UC chars are closer together than targetWordLength, keeps track of how many extra characters are required to fit the target length of the abbreviation |
| 77 | 79 | $wordIndex = 0; //Set the wordIndex to reflect a new word |
| 78 | 80 | } else if ($wordIndex >= $targetWordLength) { |
| 79 | - if ($characterDeficit == 0) //If the word is full and we're not short any characters, ignore the character |
|
| 81 | + if ($characterDeficit == 0) { |
|
| 82 | + //If the word is full and we're not short any characters, ignore the character |
|
| 80 | 83 | continue; |
| 81 | - else |
|
| 82 | - $characterDefecit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 84 | + } else { |
|
| 85 | + $characterDefecit--; |
|
| 86 | + } |
|
| 87 | + //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 83 | 88 | } |
| 84 | 89 | $abbreviation .= $currentChar; //Add the character to the abbreviation |
| 85 | 90 | $abbrevLength++; //Increment abbreviation length |
@@ -114,7 +119,9 @@ discard block |
||
| 114 | 119 | $ascii['y'] = array(253, 255); |
| 115 | 120 | foreach ($ascii as $key => $item) { |
| 116 | 121 | $acentos = ''; |
| 117 | - foreach ($item AS $codigo) $acentos .= chr($codigo); |
|
| 122 | + foreach ($item AS $codigo) { |
|
| 123 | + $acentos .= chr($codigo); |
|
| 124 | + } |
|
| 118 | 125 | $troca[$key] = '/[' . $acentos . ']/i'; |
| 119 | 126 | } |
| 120 | 127 | $string = preg_replace(array_values($troca), array_keys($troca), $string); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | return sprintf($template, $file) . "\n"; |
| 47 | 47 | } |
| 48 | 48 | } else { |
| 49 | - return sprintf($template, $files) . "\n"; |
|
| 49 | + return sprintf($template, $files) . "\n"; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | if (is_array($files)) { |
| 56 | 56 | foreach ($files as $key => $value) { |
| 57 | - echo static::resource($value, 'js'); |
|
| 57 | + echo static::resource($value, 'js'); |
|
| 58 | 58 | } |
| 59 | 59 | } else { |
| 60 | 60 | echo static::resource($files, 'js'); |