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

Commit 04a2881

Browse files
committed
Merge branch 'hotfix/140'
Close #140
2 parents af13903 + 8c9f355 commit 04a2881

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.
@@ -18,7 +22,14 @@ All notable changes to this project will be documented in this file, in reverse
1822

1923
### Fixed
2024

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

2334
## 3.3.0 - 2017-10-20
2435

@@ -257,6 +268,9 @@ All notable changes to this project will be documented in this file, in reverse
257268

258269
### Changed
259270

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

src/Scanner/MethodScanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ public function setName($name)
279279
*
280280
* @param int $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
281281
* @return self
282-
* @throws \Zend\Code\Exception
282+
* @throws \Zend\Code\Exception\InvalidArgumentException
283283
*/
284284
public function setVisibility($visibility)
285285
{
286-
switch (strtolower($visibility)) {
286+
switch ($visibility) {
287287
case T_PUBLIC:
288288
$this->isPublic = true;
289289
$this->isPrivate = false;
@@ -303,7 +303,7 @@ public function setVisibility($visibility)
303303
break;
304304

305305
default:
306-
throw new Exception('Invalid visibility argument passed to setVisibility.');
306+
throw new Exception\InvalidArgumentException('Invalid visibility argument passed to setVisibility.');
307307
}
308308

309309
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)