summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Statement.php6
-rw-r--r--src/UtfString.php5
-rw-r--r--src/Utils/Formatter.php57
3 files changed, 32 insertions, 36 deletions
diff --git a/src/Statement.php b/src/Statement.php
index a0a2b17..523683a 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -479,11 +479,11 @@ abstract class Statement
// Handle ordering of Multiple Joins in a query
if ($clauseStartIdx != -1) {
- if ($joinStart == 0 && stripos($clauseType, 'JOIN')) {
+ if ($joinStart == 0 && stripos($clauseType, 'JOIN') !== false) {
$joinStart = 1;
- } elseif ($joinStart == 1 && ! stripos($clauseType, 'JOIN')) {
+ } elseif ($joinStart == 1 && stripos($clauseType, 'JOIN') === false) {
$joinStart = 2;
- } elseif ($joinStart == 2 && stripos($clauseType, 'JOIN')) {
+ } elseif ($joinStart == 2 && stripos($clauseType, 'JOIN') !== false) {
$error = 1;
}
}
diff --git a/src/UtfString.php b/src/UtfString.php
index 8b53a6d..66ec4e4 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -76,10 +76,7 @@ class UtfString implements \ArrayAccess
$this->str = $str;
$this->byteIdx = 0;
$this->charIdx = 0;
- // TODO: `strlen($str)` might return a wrong length when function
- // overloading is enabled.
- // https://php.net/manual/ro/mbstring.overload.php
- $this->byteLen = strlen($str);
+ $this->byteLen = mb_strlen($str, '8bit');
$this->charLen = mb_strlen($str, 'UTF-8');
}
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index 51f8633..e459b60 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -71,7 +71,11 @@ class Formatter
$options
);
- $options['formats'] = self::mergeFormats($this->getDefaultFormats(), @$options['formats'] ?: array());
+ if (isset($options['formats'])) {
+ $options['formats'] = self::mergeFormats($this->getDefaultFormats(), $options['formats']);
+ } else {
+ $options['formats'] = $this->getDefaultFormats();
+ }
if (is_null($options['line_ending'])) {
$options['line_ending'] = $options['type'] === 'html' ? '<br/>' : "\n";
@@ -208,44 +212,39 @@ class Formatter
private static function mergeFormats(array $formats, array $newFormats)
{
$added = array();
+ $integers = array('flags', 'type');
+ $strings = array('html', 'cli', 'function');
+ /* Sanitize the array so that we do not have to care later */
+ foreach ($newFormats as $j => $new) {
+ foreach ($integers as $name) {
+ if (! isset($new[$name])) {
+ $newFormats[$j][$name] = 0;
+ }
+ }
+ foreach ($strings as $name) {
+ if (! isset($new[$name])) {
+ $newFormats[$j][$name] = '';
+ }
+ }
+ }
+
+ /* Process changes to existing formats */
foreach ($formats as $i => $original) {
foreach ($newFormats as $j => $new) {
- if (isset($new['type'])
- && $new['type'] === $original['type']
- && (
- (
- isset($new['flags'])
- && $original['flags'] === $new['flags']
- )
- || (
- !isset($new['flags'])
- && $original['flags'] == 0
- )
- )
+ if ($new['type'] === $original['type']
+ && $original['flags'] === $new['flags']
) {
- $formats[$i] = array(
- 'type' => $original['type'],
- 'flags' => isset($new['flags']) ? $new['flags'] : 0,
- 'html' => isset($new['html']) ? $new['html'] : '',
- 'cli' => isset($new['cli']) ? $new['cli'] : '',
- 'function' => isset($new['function']) ? $new['function'] : '',
- );
-
+ $formats[$i] = $new;
$added[] = $j;
}
}
}
+ /* Add not already handled formats */
foreach ($newFormats as $j => $new) {
- if (!in_array($j, $added) && isset($new['type'])) {
- $formats[] = array(
- 'type' => $new['type'],
- 'flags' => isset($new['flags']) ? $new['flags'] : 0,
- 'html' => isset($new['html']) ? $new['html'] : '',
- 'cli' => isset($new['cli']) ? $new['cli'] : '',
- 'function' => isset($new['function']) ? $new['function'] : '',
- );
+ if (! in_array($j, $added)) {
+ $formats[] = $new;
}
}