Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/Curl/CaseInsensitiveArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Curl;

class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
{
private $container = array();

public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->container[] = $value;
} else {
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if (!($index === false)) {
$keys = array_keys($this->container);
unset($this->container[$keys[$index]]);
}
$this->container[$offset] = $value;
}
}

public function offsetExists($offset)
{
return array_key_exists(strtolower($offset), array_change_key_case($this->container, CASE_LOWER));
}

public function offsetUnset($offset)
{
unset($this->container[$offset]);
}

public function offsetGet($offset)
{
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if ($index === false) {
return null;
}

$values = array_values($this->container);
return $values[$index];
}

public function count()
{
return count($this->container);
}

public function current()
{
return current($this->container);
}

public function next()
{
return next($this->container);
}

public function key()
{
return key($this->container);
}

public function valid()
{
return !($this->current() === false);
}

public function rewind()
{
reset($this->container);
}
}
72 changes: 1 addition & 71 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Curl
{
const VERSION = '4.8.0';
const VERSION = '4.8.1';
const DEFAULT_TIMEOUT = 30;

public $curl;
Expand Down Expand Up @@ -997,73 +997,3 @@ public static function is_array_multidim($array)
return (bool)count(array_filter($array, 'is_array'));
}
}

class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
{
private $container = array();

public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->container[] = $value;
} else {
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if (!($index === false)) {
$keys = array_keys($this->container);
unset($this->container[$keys[$index]]);
}
$this->container[$offset] = $value;
}
}

public function offsetExists($offset)
{
return array_key_exists(strtolower($offset), array_change_key_case($this->container, CASE_LOWER));
}

public function offsetUnset($offset)
{
unset($this->container[$offset]);
}

public function offsetGet($offset)
{
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if ($index === false) {
return null;
}

$values = array_values($this->container);
return $values[$index];
}

public function count()
{
return count($this->container);
}

public function current()
{
return current($this->container);
}

public function next()
{
return next($this->container);
}

public function key()
{
return key($this->container);
}

public function valid()
{
return !($this->current() === false);
}

public function rewind()
{
reset($this->container);
}
}
2 changes: 0 additions & 2 deletions tests/PHPCurlClass/PHPCurlClassTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
require '../src/Curl/Curl.php';
require 'Helper.php';

use \Curl\Curl;
use \Curl\CaseInsensitiveArray;
Expand Down
1 change: 0 additions & 1 deletion tests/PHPCurlClass/PHPMultiCurlClassTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
require '../src/Curl/MultiCurl.php';

use \Curl\MultiCurl;
use \Helper\Test;
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPCurlClass/server.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require 'Helper.php';
require_once 'Helper.php';

use \Helper\Test;

Expand Down
4 changes: 4 additions & 0 deletions tests/before_script.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
echo "TRAVIS_PHP_VERSION: ${TRAVIS_PHP_VERSION}"

composer self-update
composer install --prefer-source --no-interaction

if [[ "${TRAVIS_PHP_VERSION}" == "5.3" ]]; then
sudo add-apt-repository -y ppa:nginx/development
sudo apt-get update
Expand Down
13 changes: 6 additions & 7 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<phpunit>
<testsuite name="PHPCurlClass">
<directory>.</directory>
</testsuite>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" />
</logging>
<phpunit bootstrap="../vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="PHPCurlClass">
<directory suffix=".php">./PHPCurlClass/</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 7 additions & 7 deletions tests/script.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Check syntax in php files.
find . -type "f" -iname "*.php" -exec php -l {} \;
find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec php -l {} \;

# Run tests.
cd tests && phpunit --configuration phpunit.xml
phpunit --configuration tests/phpunit.xml
if [[ "${?}" -ne 0 ]]; then
exit 1
fi

# Enforce line ending consistency in php files.
crlf_file=$(find . -type "f" -iname "*.php" -exec grep --files-with-matches $'\r' {} \;)
crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --files-with-matches $'\r' {} \;)
if [[ ! -z "${crlf_file}" ]]; then
echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
exit 1
fi

# Enforce indentation character consistency in php files.
tab_char=$(find . -type "f" -iname "*.php" -exec grep --line-number -H --perl-regexp "\t" {} \;)
tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --line-number -H --perl-regexp "\t" {} \;)
if [[ ! -z "${tab_char}" ]]; then
echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
exit 1
Expand Down Expand Up @@ -50,22 +50,22 @@ EOF
# Skip hhvm "Notice: File could not be loaded: ..."
if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]]; then
export -f "find_invalid_indentation"
invalid_indentation=$(find . -type "f" -iname "*.php" -exec bash -c 'find_invalid_indentation "{}"' \;)
invalid_indentation=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;)
if [[ ! -z "${invalid_indentation}" ]]; then
echo "${invalid_indentation}"
exit 1
fi
fi

# Prohibit trailing whitespace in php files.
trailing_whitespace=$(find . -type "f" -iname "*.php" -exec egrep --line-number -H " +$" {} \;)
trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --line-number -H " +$" {} \;)
if [[ ! -z "${trailing_whitespace}" ]]; then
echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/'
exit 1
fi

# Prohibit long lines in php files.
long_lines=$(find . -type "f" -iname "*.php" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120')
long_lines=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120')
if [[ ! -z "${long_lines}" ]]; then
echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/'
exit 1
Expand Down