Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Mar 29, 2017
2 parents 837760a + 77f50b0 commit 6d05ada
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 37 deletions.
16 changes: 12 additions & 4 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('tests')
->in(__DIR__);

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->finder($finder);
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules(array(
'@PSR2' => true,
'binary_operator_spaces' => true,
'no_whitespace_in_blank_line' => true,
'ternary_operator_spaces' => true,
'cast_spaces' => true,
'trailing_comma_in_multiline_array' => true
))
->setFinder($finder);
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ php:
- 5.4
- 5.5
- 5.6
- 7
- 7.0
- 7.1

before_install:
- composer self-update

install:
- composer install --no-dev
- composer install

script:
- phpunit --coverage-text --coverage-clover=coverage.clover
- ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 1.2.0
- issue #7 - Improve Exception message

## 1.1.0
- issue #5 - No autocomplete because of return type on a new line after @return in annotation

Expand Down
45 changes: 22 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "wsdltophp/phpgenerator",
"description": "Generate php source file",
"type": "library",
"keywords" : ["php","generator"],
"homepage" : "https://github.com/WsdlToPhp/PhpGenerator",
"license" : "MIT",
"authors" : [
{
"name": "Mikaël DELSOL",
"email": "contact@wsdltophp.com",
"role": "Owner"
}
],
"support" : {
"email" : "contact@wsdltophp.com"
},
"require": {
"name" : "wsdltophp/phpgenerator",
"description" : "Generate php source file",
"require" : {
"php" : ">=5.3.3"
},
"require-dev": {
"fabpot/php-cs-fixer": "~1.8"
"friendsofphp/php-cs-fixer": "~2.0",
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-4": {
"WsdlToPhp\\PhpGenerator\\": "src",
"WsdlToPhp\\PhpGenerator\\Tests\\": "tests"
"license" : "MIT",
"keywords" : [ "php", "generator" ],
"autoload" : {
"psr-4" : {
"WsdlToPhp\\PhpGenerator\\" : "src",
"WsdlToPhp\\PhpGenerator\\Tests\\" : "tests"
}
}
},
"type" : "library",
"support" : {
"email" : "contact@wsdltophp.com"
},
"homepage" : "https://github.com/WsdlToPhp/PhpGenerator",
"authors" : [ {
"name" : "Mikaël DELSOL",
"email" : "contact@wsdltophp.com",
"role" : "Owner"
} ]
}
2 changes: 1 addition & 1 deletion src/Element/AbstractAssignedValueElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($name, $value = null, $access = parent::ACCESS_PUBLI
public function setValue($value)
{
if ($this->getAcceptNonScalarValue() === false && !is_scalar($value) && $value !== null) {
throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value', gettype($value)));
throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value for %s object', gettype($value), $this->getCalledClass()));
}
$this->value = $value;
return $this;
Expand Down
13 changes: 10 additions & 3 deletions src/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($name)
public function setName($name)
{
if (!self::nameIsValid($name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" is invalid, please provide a valid name', $name));
throw new \InvalidArgumentException(sprintf('Name "%s" is invalid when instantiating %s object', $name, $this->getCalledClass()));
}
$this->name = $name;
return $this;
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function childIsValid($child)
$valid |= (gettype($child) === $authorizedType) || self::objectIsValid($child, $authorizedType);
}
}
return (bool)$valid;
return (bool) $valid;
}
/**
* @return AbstractElement[]|mixed[]
Expand Down Expand Up @@ -324,9 +324,16 @@ public function getIndentationString($indentation = null)
public function getIndentedString($string, $indentation = null)
{
$strings = explode(self::BREAK_LINE_CHAR, $string);
foreach ($strings as $i=>$s) {
foreach ($strings as $i => $s) {
$strings[$i] = sprintf('%s%s', $this->getIndentationString($indentation), $s);
}
return implode(self::BREAK_LINE_CHAR, $strings);
}
/**
* @return string
*/
final public function getCalledClass()
{
return substr(get_called_class(), strrpos(get_called_class(), '\\') + 1);
}
}
2 changes: 1 addition & 1 deletion src/Element/PhpAnnotationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected static function annotationsAreValid(array $annotations)
foreach ($annotations as $annotation) {
$valid &= self::annotationIsValid($annotation);
}
return (bool)$valid;
return (bool) $valid;
}
/**
* @param string|array|PhpAnnotation $annotation
Expand Down
2 changes: 1 addition & 1 deletion src/Element/PhpClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function interfacesAreValid(array $interfaces = array())
foreach ($interfaces as $interface) {
$valid &= self::interfaceIsValid($interface);
}
return (bool)$valid;
return (bool) $valid;
}
/**
* @param string|PhpClass $interface
Expand Down
2 changes: 1 addition & 1 deletion src/Element/PhpFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function parametersAreValid(array $parameters)
foreach ($parameters as $parameter) {
$valid &= self::parameterIsValid($parameter);
}
return (bool)$valid;
return (bool) $valid;
}
/**
* @param string|array|PhpFunctionParameter $parameter
Expand Down
9 changes: 9 additions & 0 deletions tests/Element/PhpAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ public function testHasContent()

$this->assertTrue($annotation->hasContent());
}

public function testExceptionMessageOnName()
{
try {
new PhpAnnotation(0, '');
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpAnnotation object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,13 @@ public function testExtendsFromNamespace()

$this->assertSame("class Foo extends \\DOMDocument\n{\n}", $class->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpClass(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpClass object', $e->getMessage());
}
}
}
18 changes: 18 additions & 0 deletions tests/Element/PhpConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,22 @@ public function testGetChildrenTypes()

$this->assertSame(array(), $constant->getChildrenTypes());
}

public function testExceptionMessageOnName()
{
try {
new PhpConstant(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpConstant object', $e->getMessage());
}
}

public function testExceptionMessageOnValue()
{
try {
new PhpConstant('Foo', new \stdClass());
} catch (\InvalidArgumentException $e) {
$this->assertSame('Value of type "object" is not a valid scalar value for PhpConstant object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ public function testAnnotationClassMethodBlockToString()

$this->assertSame("<?php\n/**\n * date is the key\n * time is the core key\n */\nclass Foo\n{\n public function Bar()\n {\n }\n}\n", $file->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpFile(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpFile object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpFunctionParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ public function testToStringWithNamespace()

$this->assertSame('My\Name\Space $foo = null', $functionParameter->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpFunctionParameter(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpFunctionParameter object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,13 @@ public function testToStringWithBody()

$this->assertSame("function foo(\$bar, \$demo = 1, \$sample = null, \$deamon = true)\n{\n \$bar = 1;\n return \$bar;\n}", $function->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpFunction(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpFunction object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,13 @@ public function testSimpleIntefaceEmptyPublicMethodToString()

$this->assertSame("interface Foo\n{\n public function bar();\n}", $interface->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpInterface(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpInterface object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ public function testPublicWithBodyToString()

$this->assertSame("public function foo(\$bar, \$demo = 1, \$sample = null, \$deamon = true)\n{\n \$bar = 1;\n return \$bar;\n}", $method->toString());
}

public function testExceptionMessageOnName()
{
try {
new PhpMethod(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpMethod object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ public function testSetAccess()

$property->setAccess(' public');
}

public function testExceptionMessageOnName()
{
try {
new PhpProperty(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpProperty object', $e->getMessage());
}
}
}
9 changes: 9 additions & 0 deletions tests/Element/PhpVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,13 @@ public function testé()
$é = 4;
$this->assertEquals(4, $é);
}

public function testExceptionMessageOnName()
{
try {
new PhpVariable(0);
} catch (\InvalidArgumentException $e) {
$this->assertSame('Name "0" is invalid when instantiating PhpVariable object', $e->getMessage());
}
}
}

0 comments on commit 6d05ada

Please sign in to comment.