Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constant assignment check #746

Merged
merged 1 commit into from
Nov 11, 2022
Merged
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
99 changes: 99 additions & 0 deletions specs/const/assignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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' => 'Constant assignment',
// 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' => [],
],

'Constant assignment in the global namespace' => <<<'PHP'
<?php

$x = DIRECTORY_SEPARATOR;
$x = Client::class;
$x = Client::VERSION;
$x = \Client::class;
$x = \Client::VERSION;
$x = Guzzle\Client::class;
$x = Guzzle\Client::VERSION;
$x = \Guzzle\Client::class;
$x = \Guzzle\Client::VERSION;

----
<?php

namespace Humbug;

$x = \DIRECTORY_SEPARATOR;
$x = Client::class;
$x = Client::VERSION;
$x = \Humbug\Client::class;
$x = \Humbug\Client::VERSION;
$x = Guzzle\Client::class;
$x = Guzzle\Client::VERSION;
$x = \Humbug\Guzzle\Client::class;
$x = \Humbug\Guzzle\Client::VERSION;

PHP,

'Constant assignment in a namespace' => <<<'PHP'
<?php

namespace Acme;

$x = DIRECTORY_SEPARATOR;
$x = Client::class;
$x = Client::VERSION;
$x = \Client::class;
$x = \Client::VERSION;
$x = Guzzle\Client::class;
$x = Guzzle\Client::VERSION;
$x = \Guzzle\Client::class;
$x = \Guzzle\Client::VERSION;

----
<?php

namespace Humbug\Acme;

$x = \DIRECTORY_SEPARATOR;
$x = Client::class;
$x = Client::VERSION;
$x = \Humbug\Client::class;
$x = \Humbug\Client::VERSION;
$x = Guzzle\Client::class;
$x = Guzzle\Client::VERSION;
$x = \Humbug\Guzzle\Client::class;
$x = \Humbug\Guzzle\Client::VERSION;

PHP,
];