-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return [ | ||
'meta' => [ | ||
'title' => 'Enum declaration', | ||
// Default values. If not specified will be the one used | ||
'prefix' => 'Humbug', | ||
|
||
'expose-global-constants' => false, | ||
'expose-global-classes' => false, | ||
'expose-global-functions' => false, | ||
'expose-namespaces' => [], | ||
'expose-constants' => [], | ||
'expose-classes' => [], | ||
'expose-functions' => [], | ||
|
||
'exclude-namespaces' => [], | ||
'exclude-constants' => [], | ||
'exclude-classes' => [], | ||
'exclude-functions' => [], | ||
|
||
'expected-recorded-classes' => [], | ||
'expected-recorded-functions' => [], | ||
], | ||
|
||
'minimal enum declaration' => <<<'PHP' | ||
<?php | ||
enum Status { | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status | ||
{ | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
|
||
PHP, | ||
|
||
'enum with methods' => <<<'PHP' | ||
<?php | ||
enum Status { | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
public function color(): string { | ||
return match($this) { | ||
Status::DRAFT => 'grey', | ||
Status::PUBLISHED => 'green', | ||
self::ARCHIVED => 'red', | ||
}; | ||
} | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status | ||
{ | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
public function color() : string | ||
{ | ||
return match ($this) { | ||
Status::DRAFT => 'grey', | ||
Status::PUBLISHED => 'green', | ||
self::ARCHIVED => 'red', | ||
}; | ||
} | ||
} | ||
|
||
PHP, | ||
|
||
'enum with interface' => <<<'PHP' | ||
<?php | ||
enum Status implements HasColor { | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status implements \HasColor | ||
{ | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} | ||
|
||
PHP, | ||
|
||
'class with Enum name' => <<<'PHP' | ||
<?php | ||
class Enum {} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
class Enum | ||
{ | ||
} | ||
|
||
PHP, | ||
|
||
'backed enum' => <<<'PHP' | ||
<?php | ||
enum Status: string { | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status : string | ||
{ | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} | ||
|
||
PHP, | ||
|
||
'excluded enum (doesn\'t work)' => [ | ||
'exclude-classes' => ['Status'], | ||
'payload' => <<<'PHP' | ||
<?php | ||
enum Status { | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status | ||
{ | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
|
||
PHP | ||
], | ||
|
||
'exposed enum (doesn\'t work)' => [ | ||
'expose-classes' => ['Status'], | ||
'payload' => <<<'PHP' | ||
<?php | ||
enum Status { | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
---- | ||
<?php | ||
namespace Humbug; | ||
enum Status | ||
{ | ||
case DRAFT; | ||
case PUBLISHED; | ||
case ARCHIVED; | ||
} | ||
|
||
PHP | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return [ | ||
'meta' => [ | ||
'title' => 'Enum declaration', | ||
// Default values. If not specified will be the one used | ||
'prefix' => 'Humbug', | ||
|
||
'expose-global-constants' => false, | ||
'expose-global-classes' => false, | ||
'expose-global-functions' => false, | ||
'expose-namespaces' => [], | ||
'expose-constants' => [], | ||
'expose-classes' => [], | ||
'expose-functions' => [], | ||
|
||
'exclude-namespaces' => [], | ||
'exclude-constants' => [], | ||
'exclude-classes' => [], | ||
'exclude-functions' => [], | ||
|
||
'expected-recorded-classes' => [], | ||
'expected-recorded-functions' => [], | ||
], | ||
|
||
'typehint and create an enum' => <<<'PHP' | ||
<?php | ||
namespace Acme; | ||
use Status; | ||
class BlogPost | ||
{ | ||
public function __construct( | ||
public Status $status, | ||
) {} | ||
} | ||
$post = new BlogPost(Status::DRAFT); | ||
---- | ||
<?php | ||
namespace Humbug\Acme; | ||
use Humbug\Status; | ||
class BlogPost | ||
{ | ||
public function __construct(public Status $status) | ||
{ | ||
} | ||
} | ||
$post = new BlogPost(Status::DRAFT); | ||
|
||
PHP, | ||
|
||
'use an enum method' => <<<'PHP' | ||
<?php | ||
namespace Acme; | ||
use Status; | ||
$status = Status::ARCHIVED; | ||
$status->color(); | ||
---- | ||
<?php | ||
namespace Humbug\Acme; | ||
use Humbug\Status; | ||
$status = Status::ARCHIVED; | ||
$status->color(); | ||
|
||
PHP, | ||
|
||
'use instance of enum' => <<<'PHP' | ||
<?php | ||
namespace Acme; | ||
$statusC instanceof \Post\Status; | ||
---- | ||
<?php | ||
namespace Humbug\Acme; | ||
$statusC instanceof \Humbug\Post\Status; | ||
|
||
PHP, | ||
]; |