Skip to content

Commit

Permalink
fix: compatibility with PHP 7.1 and 7.2 (#60)
Browse files Browse the repository at this point in the history
* Added PHP 8 to CI
* Added code style checking
  • Loading branch information
bednar authored Jan 4, 2021
1 parent 43e8fa0 commit fdb2667
Show file tree
Hide file tree
Showing 40 changed files with 359 additions and 478 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,25 @@ jobs:
export PATH=/c/tools/php/:$PATH
./vendor/bin/phpunit --exclude-group "integration" --log-junit build/junit.xml
- storing-test-results
check-code-style:
docker:
- image: *default-php-image
steps:
- checkout
- run: |
mkdir -p tools/php-cs-fixer
composer require --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=estimating --using-cache=no --diff
workflows:
version: 2
build:
jobs:
- tests-php:
name: php-7.4
- tests-php:
name: php-8.0
php-image: "circleci/php:8.0"
- tests-php:
name: php-7.4-guzzle-7
guzzle-version: "7.0.1"
Expand All @@ -134,6 +146,7 @@ workflows:
php-image: "circleci/php:7.1"
- tests-windows:
name: php-windows
- check-code-style

nightly:
triggers:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
bin/
vendor/
composer.lock
composer.lock*
build/
.idea/
coverage.xml
/scripts/.m2/
/generated/
/*.iml
log_test.txt
tree.txt
/.php_cs.cache
/tools/
11 changes: 11 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
return PhpCsFixer\Config::create()
->setFinder(
PhpCsFixer\Finder::create()
->exclude('src/InfluxDB2/Model')
->exclude('src/InfluxDB2/Service')
->notPath('src/InfluxDB2/HeaderSelector.php')
->notPath('src/InfluxDB2/ObjectSerializer.php')
->in(__DIR__)
)
;
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
1. [#53](https://github.com/influxdata/influxdb-client-php/pull/53): Ability to write via UDP protocol
1. [#57](https://github.com/influxdata/influxdb-client-php/pull/57): Added possibility to disable verification of SSL certificate

### Bug Fixes
1. [#60](https://github.com/influxdata/influxdb-client-php/pull/60): Compatibility with PHP 7.1 and 7.2

### CI
1. [#58](https://github.com/influxdata/influxdb-client-php/pull/58): Updated default docker image to v2.0.3
1. [#60](https://github.com/influxdata/influxdb-client-php/pull/60): Added PHP 8 to CI, Added code style checking to CI

## 1.9.0 [2020-12-04]

Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"guzzlehttp/guzzle": "^6.2|^7.0.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.12",
"phpspec/phpspec": ">5.0",
"phpunit/phpunit": "^7.4",
"phpunit/phpunit": "^7.4|^9.1",
"squizlabs/php_codesniffer": "~2.6"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions examples/WriteBatchingExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
print "*** Write by batching ***\n";

$writeApi = $client->createWriteApi(
["writeType" => WriteType::BATCHING, 'batchSize' => 1000]);
["writeType" => WriteType::BATCHING, 'batchSize' => 1000]
);

foreach (range(1, 10000) as $number) {
$writeApi->write("mem,host=aws_europe,type=batch value=1i $number");
Expand All @@ -46,4 +47,3 @@
print "Count: $value\n";

$client->close();

66 changes: 0 additions & 66 deletions spec/InfluxDB2/ApiClientSpec.php

This file was deleted.

73 changes: 0 additions & 73 deletions spec/InfluxDB2/PointSpec.php

This file was deleted.

31 changes: 0 additions & 31 deletions spec/InfluxDB2/WriteClientSpec.php

This file was deleted.

1 change: 0 additions & 1 deletion src/InfluxDB2/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function close()

public function getConfiguration()
{

$config = Configuration::getDefaultConfiguration()
->setUserAgent('influxdb-client-php/' . Client::VERSION)
->setDebug(isset($this->options['debug']) ? $this->options['debug'] : null)
Expand Down
10 changes: 4 additions & 6 deletions src/InfluxDB2/DefaultApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ private function request($payload, $uriPath, $queryParams, $method, $timeout = s
);
}
return $response;

} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
Expand All @@ -109,14 +108,14 @@ private function request($payload, $uriPath, $queryParams, $method, $timeout = s
}
}

function check($key, $value)
protected function check($key, $value)
{
if ((!isset($value) || trim($value) === '')) {
$options = implode(', ', array_map(
function ($v, $k) {
if(is_array($v)){
if (is_array($v)) {
return $k.'[]='.implode('&'.$k.'[]=', $v);
}else{
} else {
return $k.'='.$v;
}
},
Expand All @@ -133,12 +132,11 @@ function ($v, $k) {
* @param string $level log severity
* @param string $message log message
*/
function log(string $level, string $message): void
protected function log(string $level, string $message): void
{
$logFile = isset($this->options['logFile']) ? $this->options['logFile'] : "php://output";
$logDate = date('H:i:s d-M-Y');

file_put_contents($logFile, "[{$logDate}]: [{$level}] - {$message}", FILE_APPEND);
}
}

2 changes: 1 addition & 1 deletion src/InfluxDB2/FluxColumn.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace InfluxDB2;

/**
* Class FluxColumn represents a column header specification of FluxTable.
* @package InfluxDB2
Expand Down Expand Up @@ -29,5 +30,4 @@ public function __construct($index = null, $label = null, $dataType = null, $gro
$this->group = $group;
$this->defaultValue = $defaultValue;
}

}
15 changes: 6 additions & 9 deletions src/InfluxDB2/FluxCsvParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($response, $stream = false)

private function stringToStream(string $string)
{
$stream = fopen('php://memory','r+');
$stream = fopen('php://memory', 'r+');
fwrite($stream, $string);
rewind($stream);
return $stream;
Expand Down Expand Up @@ -92,8 +92,10 @@ public function each()
if ($this->parsingStateError) {
$error = $csv[1];
$referenceValue = $csv[2];
throw new FluxQueryError($error,
!isset($referenceValue) || trim($referenceValue) === '' ? 0 : $referenceValue);
throw new FluxQueryError(
$error,
!isset($referenceValue) || trim($referenceValue) === '' ? 0 : $referenceValue
);
}

$result = $this->parseLine($csv);
Expand All @@ -102,9 +104,7 @@ public function each()
yield $result;
}
}
}
finally
{
} finally {
$this->closeConnection();
}
}
Expand Down Expand Up @@ -270,15 +270,13 @@ private function toValue($strVal, FluxColumn $column)
}

return $strVal;

}

private function readline(StreamInterface $stream)
{
$buffer = null;

while (null !== ($byte = $stream->read(1))) {

if ($byte === "") {
break;
}
Expand Down Expand Up @@ -308,5 +306,4 @@ private function closeConnection()

class FluxQueryError extends RuntimeException
{

}
1 change: 0 additions & 1 deletion src/InfluxDB2/FluxCsvParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace InfluxDB2;


class FluxCsvParserException extends \RuntimeException
{
/**
Expand Down
Loading

0 comments on commit fdb2667

Please sign in to comment.