Skip to content

Commit

Permalink
Merge pull request #60 from belgattitude/php-8
Browse files Browse the repository at this point in the history
PHP 8 support
  • Loading branch information
belgattitude authored Apr 25, 2021
2 parents 2ae2d0b + 30db79c commit 0b17771
Show file tree
Hide file tree
Showing 55 changed files with 252 additions and 208 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ infection-log.txt
.travis/*.log
.travis/*.pid
/deploy_doc.sh
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build:
project_setup:
override: true
environment:
php: 7.2
php: 8.0
tests:
override: ['php-scrutinizer-run']

Expand Down
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
dist: bionic
language: php
sudo: required
dist: trusty

services:
- mysql

matrix:
fast_finish: true
include:
- php: 7.2
- php: 8.0
env:
- CS_CHECKS=true
- SEND_COVERAGE=true
- PHPSTAN=true
- INFECTION=false
- php: 7.3
- php: 7.4
env:
- INFECTION=false
- php: nightly
env:
- INFECTION=false
allow_failures:
- php: nightly

Expand Down
2 changes: 1 addition & 1 deletion .travis/launch_javabridge_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_DIR="${SCRIPT_DIR}/.."

# soluble PHPJavabridge version
PJB_VERSION="7.1.3"
PJB_VERSION="7.2.0-beta.1"
PJB_DIR="${SCRIPT_DIR}/downloads/php-java-bridge-${PJB_VERSION}"

# Webapp runner properties
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 3.0.0 (2021-04-19)

### New

- PHP 8.0 support in [#60](https://github.com/belgattitude/soluble-japha/pull/60)

### Changed

- Dropped support for PHP versions below 7.4 in [#60](https://github.com/belgattitude/soluble-japha/pull/60)

### Fixed

- TimeZoneUtils: propertly casting timezone ids into string in [#60](https://github.com/belgattitude/soluble-japha/pull/60)

### Dev

- [Q&A] update phpunit, phpstan and cs-fixer, in [#60](https://github.com/belgattitude/soluble-japha/pull/60)


## 2.8.1 (2020-07-10)

### Changed
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# soluble-japha

[![PHP Version](https://img.shields.io/badge/php-5.5+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-7.1+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-7.4+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-8.0+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![Build Status](https://travis-ci.org/belgattitude/soluble-japha.svg?branch=master)](https://travis-ci.org/belgattitude/soluble-japha)
[![codecov](https://codecov.io/gh/belgattitude/soluble-japha/branch/master/graph/badge.svg)](https://codecov.io/gh/belgattitude/soluble-japha)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/belgattitude/soluble-japha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/belgattitude/soluble-japha/?branch=master)
Expand Down Expand Up @@ -118,14 +118,14 @@ to take advantage of
## Requirements

- Version `^3.0` requires PHP 8.0 ![PHP Version](http://img.shields.io/badge/php-8.0+-ff69b4.svg)
- Version `^2.0` requires PHP 7.1 ![PHP Version](http://img.shields.io/badge/php-7.1+-ff69b4.svg)

> **Important**. There's **NO API BC-BREAK** between v0.13, v1.x and v2.x so you should be
> **Important**. There's **NO API BC-BREAK** between v0.13, v1.x, v2.x and v3.x so you should be
> able to upgrade safely between releases. The choice to increment version numbers to drop
> support for older php versions was made to avoid any confusion with multiple php installs.


If you're looking for compatibility with older PHP versions, note that:

- Version `^1.0` requires PHP 5.6 ![PHP Version](http://img.shields.io/badge/php-5.6+-ff69b4.svg) and works with HHVM.
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
},
"require": {
"ext-xml": "*",
"php": "^7.2",
"psr/log": "^1.0"
"php": "^7.4.0 || ^8.0.0",
"psr/log": "^1.1"
},
"require-dev" : {
"phpunit/phpunit": "^7.5",
"friendsofphp/php-cs-fixer": "^2.16.4",
"monolog/monolog": "^2.0",
"phpstan/phpstan": "^0.12.32",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"belgattitude/pjbserver-tools": "^3.1",
"infection/infection": "^0.14"
"phpunit/phpunit": "^9.5.4",
"friendsofphp/php-cs-fixer": "v2.18.5",
"monolog/monolog": "^2.2.0",
"phpstan/phpstan": "^0.12.84",
"phpstan/phpstan-strict-rules": "^0.12.9",
"phpstan/phpstan-phpunit": "^0.12.17",
"belgattitude/pjbserver-tools": "^3.1.0 || ^4.0",
"infection/infection": "^0.21.5",
"dms/phpunit-arraysubset-asserts": "^v0.2.1"
},
"scripts": {
"check": [
Expand Down
1 change: 1 addition & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Latest Stable Version](https://poser.pugx.org/soluble/japha/v/stable.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-5.5+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-7.1+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![PHP Version](https://img.shields.io/badge/php-8.0+-ff69b4.svg)](https://packagist.org/packages/soluble/japha)
[![codecov](https://codecov.io/gh/belgattitude/soluble-japha/branch/master/graph/badge.svg)](https://codecov.io/gh/belgattitude/soluble-japha)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/belgattitude/soluble-japha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/belgattitude/soluble-japha/?branch=master)
[![Total Downloads](https://poser.pugx.org/soluble/japha/downloads.png)](https://packagist.org/packages/soluble/japha)
Expand Down
10 changes: 9 additions & 1 deletion doc/install_client.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# PHP installation

=== "PHP7.2+"

=== "PHP7.4 & PHP8.0"

```bash
$ composer require soluble/japha
```


=== "PHP7.2"

```bash
$ composer require soluble/[email protected]
```

=== "PHP7.1"

```bash
Expand Down
5 changes: 4 additions & 1 deletion src/Soluble/Japha/Bridge/Driver/Pjb62/PjbProxyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,13 @@ public function getLogger(): LoggerInterface

/**
* @throws Exception\BrokenConnectionException|Exception\AuthenticationException
*
* @return never
*/
public static function unregisterAndThrowBrokenConnectionException(string $message = null, int $code = null): void
{
if (self::$instance !== null) {
$message = $message ?? 'undefined messsage';
$message = $message ?? 'undefined message';

switch ($code) {
case 401:
Expand Down Expand Up @@ -537,6 +539,7 @@ public static function unregisterAndThrowBrokenConnectionException(string $messa
self::unregisterInstance();
throw $exception;
}
throw new Exception\BrokenConnectionException('No instance to remove');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Soluble/Japha/Util/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getAvailableIDs(): array
$this->availableTz = [];
$available = $this->timeZoneClass->getAvailableIDs();
foreach ($available as $id) {
$this->availableTz[] = $id;
$this->availableTz[] = (string) $id;
}
}

Expand Down
85 changes: 85 additions & 0 deletions test/bench/Benchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

class Benchmark
{
/**
* @var bool
*/
public $tableHeaderPrinted = false;

/**
* @var array
*/
public $iterations = [1, 100, 1000, 10000];

public function __construct()
{
}

/**
* @param string $name
* @param callable $fn
*/
public function time($name, callable $fn)
{
if (!$this->tableHeaderPrinted) {
echo '| Benchmark name | '.implode('|', array_map(function ($iter) {
return " x$iter ";
}, $this->iterations)).'| Average | Memory |'.PHP_EOL;
echo '|----| '.implode('|', array_map(function ($iter) {
return '----:';
}, $this->iterations)).'|-------:|----:| '.PHP_EOL;
$this->tableHeaderPrinted = true;
}

$times = [];

$start_memory = memory_get_usage(false);

foreach ($this->iterations as $iteration) {
$start_time = microtime(true);
$fn($iteration);
$total_time = microtime(true) - $start_time;
$times[$iteration] = $total_time;
}

$memory = memory_get_usage(false) - $start_memory;

$avg = array_sum($times) / array_sum(array_keys($times));

/*
$ttime = array_sum($times);
echo number_format($ttime * 1000, 2);
*/
echo "| $name | ".implode('| ', array_map(function ($time) {
return number_format($time * 1000, 2).'ms';
}, $times)).'| '.
number_format($avg * 1000, 2).'ms| '.
round($memory / 1024, 2).'Kb'.'|'.PHP_EOL;
}

/**
* Return formatted time .
*
* @param int $start_time
* @param int $end_time
*/
public function getFormattedTimeMs($start_time, $end_time)
{
$time = $end_time - $start_time;

return number_format($time, 0, '.', '').' ms';
}

/**
* Get ms time (only 64bits platform).
*
* @return int
*/
public function getTimeMs()
{
$mt = explode(' ', microtime());

return ((int) $mt[1]) * 1000 + ((int) round($mt[0] * 1000));
}
}
85 changes: 1 addition & 84 deletions test/bench/simple_benchmarks.php → test/bench/run-bench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

require_once __DIR__.'/../../vendor/autoload.php';
require_once __DIR__.'/Benchmark.php';

use Soluble\Japha\Bridge\Adapter as BridgeAdapter;

Expand Down Expand Up @@ -224,87 +225,3 @@ function ($iterations) use (&$phpString) {
echo '- Connection time: '.$connection_time.PHP_EOL;
echo '- Total time : '.$total_time.PHP_EOL;
echo PHP_EOL;

class Benchmark
{
/**
* @var bool
*/
public $tableHeaderPrinted = false;

/**
* @var array
*/
public $iterations = [1, 100, 1000, 10000];

public function __construct()
{
}

/**
* @param string $name
* @param callable $fn
*/
public function time($name, callable $fn)
{
if (!$this->tableHeaderPrinted) {
echo '| Benchmark name | '.implode('|', array_map(function ($iter) {
return " x$iter ";
}, $this->iterations)).'| Average | Memory |'.PHP_EOL;
echo '|----| '.implode('|', array_map(function ($iter) {
return '----:';
}, $this->iterations)).'|-------:|----:| '.PHP_EOL;
$this->tableHeaderPrinted = true;
}

$times = [];

$start_memory = memory_get_usage(false);

foreach ($this->iterations as $iteration) {
$start_time = microtime(true);
$fn($iteration);
$total_time = microtime(true) - $start_time;
$times[$iteration] = $total_time;
}

$memory = memory_get_usage(false) - $start_memory;

$avg = array_sum($times) / array_sum(array_keys($times));

/*
$ttime = array_sum($times);
echo number_format($ttime * 1000, 2);
*/
echo "| $name | ".implode('| ', array_map(function ($time) {
return number_format($time * 1000, 2).'ms';
}, $times)).'| '.
number_format($avg * 1000, 2).'ms| '.
round($memory / 1024, 2).'Kb'.'|'.PHP_EOL;
}

/**
* Return formatted time .
*
* @param int $start_time
* @param int $end_time
*/
public function getFormattedTimeMs($start_time, $end_time)
{
$time = $end_time - $start_time;

return number_format($time, 0, '.', '').' ms';
}

/**
* Get ms time (only 64bits platform).
*
* @return int
*/
public function getTimeMs()
{
$mt = explode(' ', microtime());

return ((int) $mt[1]) * 1000 + ((int) round($mt[0] * 1000));
}
}
4 changes: 2 additions & 2 deletions test/src/SolubleTest/Japha/Bridge/AdapterConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AdapterConstructorTest extends TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
protected function setUp(): void
{
\SolubleTestFactories::startJavaBridgeServer();
$this->servlet_address = \SolubleTestFactories::getJavaBridgeServerAddress();
Expand All @@ -43,7 +43,7 @@ protected function setUp()
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
protected function tearDown(): void
{
}

Expand Down
Loading

0 comments on commit 0b17771

Please sign in to comment.