Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Jan 26, 2021
2 parents 1746756 + 8b338d0 commit 8fc5436
Show file tree
Hide file tree
Showing 56 changed files with 1,477 additions and 907 deletions.
9 changes: 4 additions & 5 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM php:7.1-apache
FROM splitbrain/phpfarm:jessie

RUN apt-get update \
&& apt-get install -y git zip
RUN apt-get update && apt-get install -y git zip

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . /var/www/html
COPY . /var/www/

WORKDIR /var/www/html
WORKDIR /var/www/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendor/
composer.lock
phpunit.xml
.idea
.phpunit.result.cache
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('tests/resources')
->in(__DIR__);

return PhpCsFixer\Config::create()
Expand Down
29 changes: 21 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
language: php

sudo: false
jobs:
include:
- name: 'Tests under PHP 7.4'
php: '7.4'
dist: bionic
- name: 'Tests under PHP 8.0'
php: '8.0'
dist: bionic
- name: 'Tests under PHP nightly'
php: 'nightly'
dist: bionic

php:
- 7.1
- 7.2
fast_finish: true
allow_failures:
- php: 'nightly'

cache:
directories:
- $HOME/.composer/cache

install:
- composer install
- composer install

script:
- ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover
- php -dmemory_limit=-1 -dxdebug.mode=coverage ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- wget https://scrutinizer-ci.com/ocular.phar
- php -dmemory_limit=-1 ocular.phar code-coverage:upload --format=php-clover coverage.clover

after_success:
- bash <(curl -s https://codecov.io/bash)
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# CHANGELOG

## 3.0.0 - 2021/01/26
- use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
- Code requires PHP >= 7.4
- Code cleaning
- BC:
- `WsdlToPhp\PhpGenerator\Element\PhpFunction::__construct` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the function return type
- `WsdlToPhp\PhpGenerator\Element\PhpMethod::__construct` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type
- `WsdlToPhp\PhpGenerator\Component\PhpClass::addMethod` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type
- `WsdlToPhp\PhpGenerator\Component\PhpInterface::addMethod` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type
- Implementation of the PHP `declare` statement
- `GenerateableInterface` elements and components now implement the `__toString` method
- Update READMEs
- Update Travis CI settings
- Update PHPUnit settings
- Update LICENSE file
- Version 2.0 is no more maintained

## 2.0.0
- Use PHP 7.1 features
- Refactore code
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2015 Mikaël DELSOL
Copyright (c) 2012-2021 Mikaël DELSOL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Build Status](https://api.travis-ci.org/WsdlToPhp/PhpGenerator.svg)](https://travis-ci.org/WsdlToPhp/PhpGenerator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WsdlToPhp/PhpGenerator/badges/quality-score.png)](https://scrutinizer-ci.com/g/WsdlToPhp/PhpGenerator/)
[![Code Coverage](https://scrutinizer-ci.com/g/WsdlToPhp/PhpGenerator/badges/coverage.png)](https://scrutinizer-ci.com/g/WsdlToPhp/PhpGenerator/)
[![Total Downloads](https://poser.pugx.org/wsdltophp/phpgenerator/downloads)](https://packagist.org/packages/wsdltophp/phpgenerator)
[![StyleCI](https://styleci.io/repos/36832375/shield)](https://styleci.io/repos/36832375)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/e55e9115-5a3f-4d37-bfd5-b01c8de579f9/mini.png)](https://insight.sensiolabs.com/projects/e55e9115-5a3f-4d37-bfd5-b01c8de579f9)

Expand All @@ -20,10 +21,27 @@ This project contains two main features:
- [Element](src/Element/README.md): generate basic elements
- [Component](src/Component/README.md): generate structured complex elements

## Unit tests
You can run the unit tests with the following command:
## Testing using [Docker](https://www.docker.com/)
Thanks to the [Docker image](https://hub.docker.com/r/splitbrain/phpfarm) of [phpfarm](https://github.com/fpoirotte/phpfarm), tests can be run locally under *any* PHP version using the cli:
- php-7.4

First of all, you need to create your container which you can do using [docker-compose](https://docs.docker.com/compose/) by running the below command line from the root directory of the project:
```bash
$ docker-compose up -d --build
```
$ cd /path/to/src/WsdlToPhp/PhpGenerator/
$ composer install
$ composer test

You then have a container named `php_generator` in which you can run `composer` commands and `php cli` commands such as:
```bash
# install deps in container (using update ensure it does use the composer.lock file if there is any)
$ docker exec -it php_generator php-7.4 /usr/bin/composer update
# run tests in container
$ docker exec -it php_generator php-7.4 -dmemory_limit=-1 vendor/bin/phpunit
```

## FAQ

If you have a question, feel free to [create an issue](https://github.com/WsdlToPhp/PackageGenerator/issues/new).

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
33 changes: 33 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# UPGRADE FROM 2.* to 3.*

The main change, apart from requiring PHP >= 7.4, is that `PhpFunction` and `PhpMethod` now accepts a `$returnType` parameter which impacts four locations:
- `WsdlToPhp\PhpGenerator\Element\PhpFunction::__construct` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the function return type
- `WsdlToPhp\PhpGenerator\Element\PhpMethod::__construct` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type
- `WsdlToPhp\PhpGenerator\Component\PhpClass::addMethod` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type
- `WsdlToPhp\PhpGenerator\Component\PhpInterface::addMethod` has a new parameter after the `$parameters` parameter named `$returnType` which is a string allowing to set the method return type

**Previously**:
```php
$phpFunction = new PhpFunction('name', ['firstParameter', 'secondParameter']);

$phpMethod = new PhpMethod('name', ['firstParameter', 'secondParameter'], PhpMethod::ACCESS_PUBLIC);

$phpClass = (new PhpClass('MyClass'))
->addMethod('name', ['firstParameter', 'secondParameter'], PhpMethod::ACCESS_PUBLIC);

$phpInterface = (new PhpInterface('MyInterface'))
->addMethod('name', ['firstParameter', 'secondParameter'], PhpMethod::ACCESS_PUBLIC);
```

**Now**:
```php
$phpFunction = new PhpFunction('name', ['firstParameter', 'secondParameter'] /*, 'int' or '?int' or '?App\\Entity\\MyEntity'*/);

$phpMethod = new PhpMethod('name', ['firstParameter', 'secondParameter'], null /*, 'int' or '?int' or '?App\\Entity\\MyEntity'*/, PhpMethod::ACCESS_PUBLIC);

$phpClass = (new PhpClass('MyClass'))
->addMethod('name', ['firstParameter', 'secondParameter'], null /*, 'int' or '?int' or '?App\\Entity\\MyEntity'*/, PhpMethod::ACCESS_PUBLIC);

$phpInterface = (new PhpInterface('MyInterface'))
->addMethod('name', ['firstParameter', 'secondParameter'], null /*, 'int' or '?int' or '?App\\Entity\\MyEntity'*/, PhpMethod::ACCESS_PUBLIC);
```
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"lint": "vendor/bin/php-cs-fixer fix --ansi --diff --verbose"
},
"require" : {
"php" : ">=7.1"
"php" : ">=7.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.0",
"phpunit/phpunit": "^4.8 || ^6.0"
"friendsofphp/php-cs-fixer": "^2.0",
"phpunit/phpunit": "^9"
},
"autoload" : {
"psr-4" : {
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ services:
context: .
dockerfile: .docker/Dockerfile
volumes:
- .:/var/www/html:rw
container_name: php_generator
- .:/var/www:rw
container_name: php_generator
40 changes: 16 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</phpunit>
57 changes: 29 additions & 28 deletions src/Component/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WsdlToPhp\PhpGenerator\Component;

use InvalidArgumentException;
use WsdlToPhp\PhpGenerator\Element\AbstractElement;
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement;
use WsdlToPhp\PhpGenerator\Element\PhpClass as PhpClassElement;
Expand All @@ -16,45 +17,48 @@ abstract class AbstractComponent implements GenerateableInterface
* @var PhpFileElement|PhpClassElement
*/
protected $mainElement;
/**
* @see \WsdlToPhp\PhpGenerator\Component\GenerateableInterface::toString()
* @return string
*/

public function __toString(): string
{
return $this->toString();
}

public function toString(): string
{
$content = [];
foreach ($this->getElements() as $element) {
$content[] = $this->getElementString($element);
}

return implode('', $content);
}

/**
* @return AbstractElement[]|string[]
*/
abstract public function getElements(): array;
/**
* @throws \InvalidArgumentException
* @param AbstractElement $element
* @return AbstractComponent
*/
public function setMainElement(AbstractElement $element): AbstractComponent

public function setMainElement(AbstractElement $element): self
{
if ($element instanceof PhpFileElement || $element instanceof PhpClassElement) {
$this->mainElement = $element;
} else {
throw new \InvalidArgumentException(sprintf('Element of type "%s" must be of type Element\PhpClass or Element\PhpFile', get_class($element)));
throw new InvalidArgumentException(sprintf('Element of type "%s" must be of type Element\PhpClass or Element\PhpFile', get_class($element)));
}

return $this;
}

/**
* @return PhpFileElement|PhpClassElement
*/
public function getMainElement(): AbstractElement
{
return $this->mainElement;
}

/**
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
* @param string|AbstractElement $element
* @return string
*/
Expand All @@ -66,46 +70,43 @@ protected function getElementString($element): string
} elseif ($element instanceof AbstractElement) {
$string = $element->toString();
}

return $string;
}
/**
* @param PhpConstantElement $constant
* @return AbstractComponent
*/
public function addConstantElement(PhpConstantElement $constant): AbstractComponent

public function addConstantElement(PhpConstantElement $constant): self
{
if (!$constant->getClass() instanceof PhpClassElement && $this->mainElement instanceof PhpClassElement) {
$constant->setClass($this->mainElement);
}
$this->mainElement->addChild($constant);

return $this;
}

/**
* @see \WsdlToPhp\PhpGenerator\Element\PhpConstant::__construct()
* @param string $name
* @param mixed $value
* @param PhpClassElement $class
* @param PhpClassElement|null $class
* @return AbstractComponent
*/
public function addConstant($name, $value = null, PhpClassElement $class = null): AbstractComponent
public function addConstant(string $name, $value = null, ?PhpClassElement $class = null): self
{
return $this->addConstantElement(new PhpConstantElement($name, $value, $class));
}
/**
* @param PhpAnnotationBlockElement $annotationBlock
* @return AbstractComponent
*/
public function addAnnotationBlockElement(PhpAnnotationBlockElement $annotationBlock): AbstractComponent

public function addAnnotationBlockElement(PhpAnnotationBlockElement $annotationBlock): self
{
$this->mainElement->addChild($annotationBlock);

return $this;
}

/**
* @see \WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock::__construct()
* @param array|string|PhpAnnotationElement $annotations
* @param array|string|PhpAnnotationBlockElement $annotations
* @return AbstractComponent
*/
public function addAnnotationBlock($annotations): AbstractComponent
public function addAnnotationBlock($annotations): self
{
return $this->addAnnotationBlockElement(new PhpAnnotationBlockElement(is_array($annotations) ? $annotations : [
$annotations,
Expand Down
6 changes: 3 additions & 3 deletions src/Component/GenerateableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

interface GenerateableInterface
{
/**
* @var string
*/
const BREAK_LINE_CHAR = "\n";

/**
* Must return the strict representation for the current element
* @return string
*/
public function toString(): string;

public function __toString(): string;
}
Loading

0 comments on commit 8fc5436

Please sign in to comment.