Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 43bd00c

Browse files
committed
Merge branch 'hotfix/140' into develop
Forward port #140
2 parents b200449 + 8c9f355 commit 43bd00c

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file, in reverse
88

99
- Nothing.
1010

11+
### Changed
12+
13+
- Nothing.
14+
1115
### Deprecated
1216

1317
- Nothing.
@@ -19,7 +23,14 @@ All notable changes to this project will be documented in this file, in reverse
1923

2024
### Fixed
2125

22-
- Nothing.
26+
- [#140](https://github.com/zendframework/zend-code/pull/140) fixes `MethodScanner::setVisibility()` such that it no longer
27+
casts the provided visibility token to lower case; this fix is necessary, as
28+
the method is supposed to expect only the appropriate
29+
`T_(PUBLIC|PROTECTED|PRIVATE)` token values, which are integers.
30+
31+
- [#140](https://github.com/zendframework/zend-code/pull/140) updates the `MethodScanner::setVisibility()` method to raise
32+
a package-specific `InvalidArgumentException` instead of the non-existent
33+
package `Exception` class when an invalid visibility is provided.
2334

2435
## 3.3.0 - 2017-10-20
2536

@@ -258,6 +269,9 @@ All notable changes to this project will be documented in this file, in reverse
258269

259270
### Changed
260271

272+
- [#140](https://github.com/zendframework/zend-code/pull/140) updates the `MethodScanner::setVisibility()` method to raise a package-specific `InvalidArgumentException` instead of
273+
the non-existent package `Exception` class when an invalid visibility is provided.
274+
261275
This section refers to breaking changes: please refer to
262276
[docs/book/migration.md](docs/book/migration.md) for migration instructions.
263277

src/Scanner/MethodScanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ public function setName($name)
265265
*
266266
* @param int $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
267267
* @return self
268-
* @throws \Zend\Code\Exception
268+
* @throws \Zend\Code\Exception\InvalidArgumentException
269269
*/
270270
public function setVisibility($visibility)
271271
{
272-
switch (strtolower($visibility)) {
272+
switch ($visibility) {
273273
case T_PUBLIC:
274274
$this->isPublic = true;
275275
$this->isPrivate = false;
@@ -289,7 +289,7 @@ public function setVisibility($visibility)
289289
break;
290290

291291
default:
292-
throw new Exception('Invalid visibility argument passed to setVisibility.');
292+
throw new Exception\InvalidArgumentException('Invalid visibility argument passed to setVisibility.');
293293
}
294294

295295
return $this;

test/Scanner/MethodScannerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPUnit\Framework\TestCase;
1313
use Zend\Code\Scanner\FileScanner;
1414
use Zend\Code\Scanner\ParameterScanner;
15+
use Zend\Code\Scanner\MethodScanner;
1516
use ZendTest\Code\TestAsset\AbstractClass;
1617
use ZendTest\Code\TestAsset\BarClass;
1718
use ZendTest\Code\TestAsset\FooClass;
@@ -110,4 +111,24 @@ public function testMethodScannerWorksWithSingleAbstractFunction()
110111

111112
self::assertTrue($method->isAbstract());
112113
}
114+
115+
public function testMethodScannerSetVisibilityThrowsInvalidArgumentException()
116+
{
117+
$methodScanner = new MethodScanner([]);
118+
119+
// make sure test argument is invalid
120+
$invalidArgument = max(T_PUBLIC, T_PROTECTED, T_PRIVATE) + 1;
121+
122+
$this->expectException('\Zend\Code\Exception\InvalidArgumentException');
123+
$methodScanner->setVisibility($invalidArgument);
124+
}
125+
126+
public function testMethodScannerSetVisibilityAcceptsIntegerTokens()
127+
{
128+
$methodScanner = new MethodScanner([]);
129+
130+
$this->assertSame($methodScanner->setVisibility(T_PUBLIC), $methodScanner);
131+
$this->assertSame($methodScanner->setVisibility(T_PROTECTED), $methodScanner);
132+
$this->assertSame($methodScanner->setVisibility(T_PRIVATE), $methodScanner);
133+
}
113134
}

0 commit comments

Comments
 (0)