Skip to content

Commit

Permalink
Merge pull request #10 from moufmouf/1.2
Browse files Browse the repository at this point in the history
Migrating to container-interop/service-provider 0.4.0
  • Loading branch information
moufmouf committed Sep 20, 2017
2 parents f1f18c2 + 8e73070 commit eb7f76d
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 202 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,7 +1,6 @@
language: php

php:
- 7.0
- 7.1

before_script:
Expand All @@ -10,7 +9,8 @@ before_script:

script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpstan analyse -l 7 src/

after_script:
- php vendor/bin/coveralls -v
8 changes: 4 additions & 4 deletions README.md
@@ -1,6 +1,6 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/yaco/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/yaco/?branch=1.0)
[![Build Status](https://travis-ci.org/thecodingmachine/yaco.svg?branch=1.0)](https://travis-ci.org/thecodingmachine/yaco)
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/yaco/badge.svg?branch=1.0&service=github)](https://coveralls.io/github/thecodingmachine/yaco?branch=1.0)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/yaco/badges/quality-score.png?b=1.2)](https://scrutinizer-ci.com/g/thecodingmachine/yaco/?branch=1.2)
[![Build Status](https://travis-ci.org/thecodingmachine/yaco.svg?branch=1.2)](https://travis-ci.org/thecodingmachine/yaco)
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/yaco/badge.svg?branch=1.2&service=github)](https://coveralls.io/github/thecodingmachine/yaco?branch=1.2)

# YACO - Yet another compiler

Expand All @@ -14,7 +14,7 @@ You can install this package through Composer:
```json
{
"require": {
"thecodingmachine/yaco": "~1.0"
"thecodingmachine/yaco": "^1.2"
}
}
```
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Expand Up @@ -14,23 +14,27 @@
}
},
"require": {
"php": ">=7.1",
"container-interop/definition-interop": "~0.2.0",
"container-interop/container-interop": "^1.0",
"jeremeamia/superclosure": "^2.0",
"mouf/picotainer": "^1.0",
"thecodingmachine/service-provider-registry": "^2.0"
"thecodingmachine/service-provider-registry": "^3.0",
"container-interop/service-provider": "^0.4"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/xhuberty/assembly"
"url": "https://github.com/xhuberty/assembly",
"no-api": true
}
],
"require-dev": {
"phpunit/phpunit": "~4.5",
"mnapoli/assembly": "dev-callable-service-providers as dev-master",
"satooshi/php-coveralls": "^1.0",
"container-interop/definition-interop-tests": "dev-master"
"container-interop/definition-interop-tests": "dev-master",
"phpstan/phpstan": "^0.8"
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
8 changes: 4 additions & 4 deletions src/Definition/AliasDefinition.php
Expand Up @@ -10,7 +10,7 @@ class AliasDefinition implements DumpableInterface
/**
* The identifier of the entry in the container.
*
* @var string
* @var string|null
*/
private $identifier;

Expand All @@ -27,7 +27,7 @@ class AliasDefinition implements DumpableInterface
* @param string|null $identifier The identifier of the entry in the container. Can be null if the entry is anonymous (declared inline in other instances)
* @param string $alias The identifier of the entry we are aliasing.
*/
public function __construct($identifier, $alias)
public function __construct(?string $identifier, $alias)
{
$this->identifier = $identifier;
$this->alias = $alias;
Expand All @@ -38,7 +38,7 @@ public function __construct($identifier, $alias)
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return $this->identifier;
}
Expand All @@ -62,7 +62,7 @@ public function getAlias()
*
* @return InlineEntryInterface
*/
public function toPhpCode($containerVariable, array $usedVariables = array())
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface
{
return new InlineEntry(sprintf('%s->get(%s)', $containerVariable, var_export($this->alias, true)), null, $usedVariables);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Definition/ClosureDefinition.php
Expand Up @@ -13,7 +13,7 @@ class ClosureDefinition implements DumpableInterface
/**
* The identifier of the instance in the container.
*
* @var string
* @var string|null
*/
private $identifier;

Expand All @@ -30,7 +30,7 @@ class ClosureDefinition implements DumpableInterface
* @param string|null $identifier The identifier of the entry in the container. Can be null if the entry is anonymous (declared inline in other instances)
* @param \Closure $closure The closure. It should not contain context (i.e. no "use" keyword in the closure definition). It should accept one compulsory parameter: the container.
*/
public function __construct($identifier, \Closure $closure)
public function __construct(?string $identifier, \Closure $closure)
{
$this->identifier = $identifier;
$this->closure = $closure;
Expand All @@ -41,7 +41,7 @@ public function __construct($identifier, \Closure $closure)
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return $this->identifier;
}
Expand All @@ -67,7 +67,7 @@ public function getClosure()
*
* @throws DefinitionException
*/
public function toPhpCode($containerVariable, array $usedVariables = array())
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface
{
// TODO: not optimal compared to previous interface!!!
$analyzer = new TokenAnalyzer();
Expand Down
8 changes: 4 additions & 4 deletions src/Definition/ConstParameterDefinition.php
Expand Up @@ -10,7 +10,7 @@ class ConstParameterDefinition implements DumpableInterface
/**
* The identifier of the instance in the container.
*
* @var string
* @var string|null
*/
private $identifier;

Expand All @@ -27,7 +27,7 @@ class ConstParameterDefinition implements DumpableInterface
* @param string|null $identifier The identifier of the entry in the container. Can be null if the entry is anonymous (declared inline in other instances)
* @param string $const The name of the constant. If it is a class constant, please pass the FQDN. For instance: "My\Class::CONSTANT"
*/
public function __construct($identifier, $const)
public function __construct(?string $identifier, string $const)
{
$this->identifier = $identifier;
$this->const = $const;
Expand All @@ -38,7 +38,7 @@ public function __construct($identifier, $const)
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return $this->identifier;
}
Expand All @@ -62,7 +62,7 @@ public function getConst()
*
* @return InlineEntryInterface
*/
public function toPhpCode($containerVariable, array $usedVariables = array())
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface
{
return new InlineEntry($this->const, null, $usedVariables, false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/DumpableInterface.php
Expand Up @@ -14,7 +14,7 @@ interface DumpableInterface
*
* @return string|null
*/
public function getIdentifier();
public function getIdentifier(): ?string;

/**
* Returns an InlineEntryInterface object representing the PHP code necessary to generate
Expand All @@ -25,5 +25,5 @@ public function getIdentifier();
*
* @return InlineEntryInterface
*/
public function toPhpCode($containerVariable, array $usedVariables = array());
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface;
}
16 changes: 8 additions & 8 deletions src/Definition/FactoryCallDefinition.php
Expand Up @@ -11,14 +11,14 @@ class FactoryCallDefinition implements DumpableInterface
/**
* The identifier of the instance in the container.
*
* @var string
* @var string|null
*/
private $identifier;

/**
* The fully qualified class name of this instance, or a fully qualified class name.
*
* @var ReferenceInterface
* @var ReferenceInterface|string
*/
private $factory;

Expand All @@ -40,11 +40,11 @@ class FactoryCallDefinition implements DumpableInterface
* Constructs an factory definition.
*
* @param string|null $identifier The identifier of the instance in the container. Can be null if the instance is anonymous (declared inline of other instances)
* @param ReferenceInterface $factory A pointer to the service that the factory method will be called upon, or a fully qualified class name
* @param ReferenceInterface|string $factory A pointer to the service that the factory method will be called upon, or a fully qualified class name
* @param string $methodName The name of the factory method
* @param array $methodArguments The parameters of the factory method
*/
public function __construct($identifier, $factory, $methodName, array $methodArguments = [])
public function __construct(?string $identifier, $factory, $methodName, array $methodArguments = [])
{
$this->identifier = $identifier;
$this->factory = $factory;
Expand All @@ -57,7 +57,7 @@ public function __construct($identifier, $factory, $methodName, array $methodArg
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return $this->identifier;
}
Expand Down Expand Up @@ -111,14 +111,14 @@ public function addMethodArgument($argument)
*
* @return InlineEntryInterface
*/
public function toPhpCode($containerVariable, array $usedVariables = array())
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface
{
$dumpedArguments = ValueUtils::dumpArguments($this->methodArguments, $containerVariable, $usedVariables);
$prependedCode = $dumpedArguments->getStatements();
if ($this->factory instanceof ReferenceInterface) {
$code = sprintf("%s->get(%s)->%s(%s);\n", $containerVariable, var_export($this->factory->getTarget(), true), $this->methodName, $dumpedArguments->getExpression());
$code = sprintf("%s->get(%s)->%s(%s)\n", $containerVariable, var_export($this->factory->getTarget(), true), $this->methodName, $dumpedArguments->getExpression());
} else {
$code = sprintf("%s::%s(%s);\n", '\\'.ltrim($this->factory, '\\'), $this->methodName, $dumpedArguments->getExpression());
$code = sprintf("%s::%s(%s)\n", '\\'.ltrim($this->factory, '\\'), $this->methodName, $dumpedArguments->getExpression());
}

return new InlineEntry($code, $prependedCode, $usedVariables);
Expand Down
14 changes: 7 additions & 7 deletions src/Definition/InlineEntry.php
Expand Up @@ -13,7 +13,7 @@ class InlineEntry implements InlineEntryInterface
private $expression;

/**
* @var string
* @var string|null
*/
private $statements;

Expand All @@ -29,11 +29,11 @@ class InlineEntry implements InlineEntryInterface

/**
* @param string $expression
* @param string $statements
* @param string|null $statements
* @param string[] $usedVariables
* @param bool $lazyEvaluation
*/
public function __construct($expression, $statements, array $usedVariables, $lazyEvaluation = true)
public function __construct(string $expression, ?string $statements, array $usedVariables, bool $lazyEvaluation = true)
{
$this->expression = $expression;
$this->statements = $statements;
Expand All @@ -53,7 +53,7 @@ public function __construct($expression, $statements, array $usedVariables, $laz
*
* @return string|null
*/
public function getStatements()
public function getStatements(): ?string
{
return $this->statements;
}
Expand All @@ -67,7 +67,7 @@ public function getStatements()
*
* @return string
*/
public function getExpression()
public function getExpression(): string
{
return $this->expression;
}
Expand All @@ -79,7 +79,7 @@ public function getExpression()
*
* @return array
*/
public function getUsedVariables()
public function getUsedVariables(): array
{
return $this->usedVariables;
}
Expand All @@ -91,7 +91,7 @@ public function getUsedVariables()
*
* @return bool
*/
public function isLazilyEvaluated()
public function isLazilyEvaluated(): bool
{
return $this->lazyEvaluation;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Definition/InlineEntryInterface.php
Expand Up @@ -19,7 +19,7 @@ interface InlineEntryInterface
*
* @return string|null
*/
public function getStatements();
public function getStatements(): ?string;

/**
* Returns the PHP expression representing the entry.
Expand All @@ -30,7 +30,7 @@ public function getStatements();
*
* @return string
*/
public function getExpression();
public function getExpression(): string;

/**
* Returns the list of variables used in the process of creating this
Expand All @@ -39,7 +39,7 @@ public function getExpression();
*
* @return array
*/
public function getUsedVariables();
public function getUsedVariables(): array;

/**
* If true, the entry will be evaluated when the `get` method is called (this is the default)
Expand All @@ -50,5 +50,5 @@ public function getUsedVariables();
*
* @return bool
*/
public function isLazilyEvaluated();
public function isLazilyEvaluated(): bool;
}
8 changes: 4 additions & 4 deletions src/Definition/ObjectDefinition.php
Expand Up @@ -11,7 +11,7 @@ class ObjectDefinition implements DumpableInterface
/**
* The identifier of the instance in the container.
*
* @var string
* @var string|null
*/
private $identifier;

Expand Down Expand Up @@ -43,7 +43,7 @@ class ObjectDefinition implements DumpableInterface
* @param string $className The fully qualified class name of this instance.
* @param array $constructorArguments A list of constructor arguments.
*/
public function __construct($identifier, $className, array $constructorArguments = array())
public function __construct(?string $identifier, string $className, array $constructorArguments = array())
{
$this->identifier = $identifier;
$this->className = '\\'.ltrim($className, '\\');
Expand All @@ -55,7 +55,7 @@ public function __construct($identifier, $className, array $constructorArguments
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return $this->identifier;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public function setProperty($propertyName, $value)
*
* @return InlineEntryInterface
*/
public function toPhpCode($containerVariable, array $usedVariables = array())
public function toPhpCode(string $containerVariable, array $usedVariables = array()): InlineEntryInterface
{
if ($this->identifier !== null) {
$variableName = $this->getIdentifier();
Expand Down

0 comments on commit eb7f76d

Please sign in to comment.