Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Support disallow_array_literal #17

Merged
merged 5 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ enable_experimental_tc_features=shape_field_check,sealed_classes
user_attributes=
disable_primitive_refinement=true
disable_static_local_variables = true
disallow_array_literal = true
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
language: generic
services: docker
env:
- HHVM_VERSION=4.18-latest
- HHVM_VERSION=4.25-latest
- HHVM_VERSION=latest
- HHVM_VERSION=nightly
install:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["hack", "router", "routing", "hhvm"],
"homepage": "https://github.com/hhvm/hack-router",
"require": {
"hhvm": "^4.18",
"hhvm": "^4.25",
"hhvm/hsl": "^4.0",
"facebook/hack-http-request-response-interfaces": "^0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/router/PrefixMatchingResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function resolveWithMap(
$regexps = $map->getRegexps();
foreach ($regexps as $regexp => $_sub_map) {
$pattern = '#^'.$regexp.'#';
$matches = [];
$matches = varray[];

if (\preg_match_with_matches($pattern, $path, inout $matches) !== 1) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/router/SimpleRegexpResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function resolve(
}
$map = $this->map[$method];
foreach ($map as $regexp => $responder) {
$matches = [];
$matches = varray[];
if (\preg_match_with_matches($regexp, $path, inout $matches) !== 1) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use type Facebook\HackTest\DataProvider;

final class ParserTest extends \Facebook\HackTest\HackTest {
public function getExamplePatterns(): array<(string, string)> {
return [
public function getExamplePatterns(): varray<(string, string)> {
return varray[
tuple('/foo', "['/foo']"),
tuple('/foo/{bar}', "['/foo/', {bar}]"),
tuple('/foo/[{bar}]', "['/foo/', ?[{bar}]]"),
Expand Down
34 changes: 17 additions & 17 deletions tests/RequestParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@

final class RequestParametersTest extends \Facebook\HackTest\HackTest {
public function testStringParam(): void {
$parts = [new StringRequestParameter(
$parts = varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)];
$data = dict['foo' => 'bar'];
expect((new RequestParameters($parts, [], $data))->getString('foo'))
expect((new RequestParameters($parts, varray[], $data))->getString('foo'))
->toBeSame('bar');
}

public function testIntParam(): void {
$parts = [new IntRequestParameter('foo')];
$parts = varray[new IntRequestParameter('foo')];
$data = dict['foo' => '123'];
expect((new RequestParameters($parts, [], $data))->getInt('foo'))->toBeSame(
expect((new RequestParameters($parts, varray[], $data))->getInt('foo'))->toBeSame(
123,
);
}

public function testFetchingStringAsInt(): void {
expect(() ==> {
$parts = [new StringRequestParameter(
$parts = varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)];
$data = dict['foo' => 'bar'];
(new RequestParameters($parts, [], $data))->getInt('foo');
(new RequestParameters($parts, varray[], $data))->getInt('foo');
})->toThrow(InvariantException::class);
}

public function testEnumParam(): void {
$parts = [new EnumRequestParameter(TestIntEnum::class, 'foo')];
$parts = varray[new EnumRequestParameter(TestIntEnum::class, 'foo')];
$data = dict['foo' => (string)TestIntEnum::BAR];
$value = (new RequestParameters($parts, [], $data))->getEnum(
$value = (new RequestParameters($parts, varray[], $data))->getEnum(
TestIntEnum::class,
'foo',
);
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testFromPattern(): void {
'bar' => '123',
'baz' => (string)TestIntEnum::FOO,
];
$params = new RequestParameters($parts, [], $data);
$params = new RequestParameters($parts, varray[], $data);
expect($params->getString('foo'))->toBeSame('some string');
expect($params->getInt('bar'))->toBeSame(123);
expect($params->getEnum(TestIntEnum::class, 'baz'))->toBeSame(
Expand All @@ -95,8 +95,8 @@ public function testFromPattern(): void {

public function testGetOptional(): void {
$params = new RequestParameters(
[],
[new StringRequestParameter(
varray[],
varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)],
Expand All @@ -107,8 +107,8 @@ public function testGetOptional(): void {

public function testGetMissingOptional(): void {
$params = new RequestParameters(
[],
[new StringRequestParameter(
varray[],
varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)],
Expand All @@ -120,8 +120,8 @@ public function testGetMissingOptional(): void {
public function testGetOptionalAsRequired(): void {
expect(() ==> {
$params = new RequestParameters(
[],
[new StringRequestParameter(
varray[],
varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)],
Expand All @@ -134,11 +134,11 @@ public function testGetOptionalAsRequired(): void {
public function testGetRequiredAsOptional(): void {
expect(() ==> {
$params = new RequestParameters(
[new StringRequestParameter(
varray[new StringRequestParameter(
StringRequestParameterSlashes::WITHOUT_SLASHES,
'foo',
)],
[],
varray[],
dict['foo' => 'bar'],
);
$params->getOptionalString('foo');
Expand Down
8 changes: 4 additions & 4 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ final class RouterTest extends \Facebook\HackTest\HackTest {
];

public function expectedMatches(
): array<(string, string, dict<string, string>)> {
return [
): varray<(string, string, dict<string, string>)> {
return varray[
tuple('/foo', '/foo', dict[]),
tuple('/foo/', '/foo/', dict[]),
tuple('/foo/bar', '/foo/bar', dict[]),
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getAllResolvers(
(function(dict<HttpMethod, dict<string, string>>): IResolver<string>),
)
> {
return [
return varray[
tuple('simple regexp', $map ==> new SimpleRegexpResolver($map)),
tuple(
'prefix matching',
Expand All @@ -110,7 +110,7 @@ public function expectedMatchesWithResolvers(
$map = dict[HttpMethod::GET => dict(self::MAP)];
$resolvers = Dict\from_entries($this->getAllResolvers());

$out = [];
$out = varray[];
$examples = $this->expectedMatches();
foreach ($resolvers as $name => $resolver) {
$resolver = $resolver($map);
Expand Down
4 changes: 2 additions & 2 deletions tests/UriPatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function testIntParamAssertSucceeds(): void {
)->toBeSame((new IntRequestParameter('foo'))->assert('123'));
}

public function exampleInvalidInts(): array<array<string>> {
return [['foo'], ['0123foo'], ['0.123foo'], ['0.123'], ['0x1e3']];
public function exampleInvalidInts(): varray<varray<string>> {
return varray[varray['foo'], varray['0123foo'], varray['0.123foo'], varray['0.123'], varray['0x1e3']];
}

<<DataProvider('exampleInvalidInts')>>
Expand Down