Skip to content

Commit

Permalink
Introduce NotInstantiable trait (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Nov 20, 2022
1 parent 7f74ecb commit 37d86c3
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/Configuration/ConfigurationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

namespace Humbug\PhpScoper\Configuration;

use Humbug\PhpScoper\NotInstantiable;

final class ConfigurationKeys
{
use NotInstantiable;

public const PREFIX_KEYWORD = 'prefix';
public const OUTPUT_DIR_KEYWORD = 'output-dir';
public const EXCLUDED_FILES_KEYWORD = 'exclude-files';
Expand Down Expand Up @@ -54,8 +58,4 @@ final class ConfigurationKeys
self::FUNCTIONS_INTERNAL_SYMBOLS_KEYWORD,
self::CONSTANTS_INTERNAL_SYMBOLS_KEYWORD,
];

private function __construct()
{
}
}
3 changes: 3 additions & 0 deletions src/Configuration/SymbolsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

namespace Humbug\PhpScoper\Configuration;

use Humbug\PhpScoper\NotInstantiable;
use Humbug\PhpScoper\Symbol\NamespaceRegistry;
use Humbug\PhpScoper\Symbol\SymbolRegistry;

final class SymbolsConfiguration
{
use NotInstantiable;

// To keep in sync with the default configuration set in src/scoper.inc.php.tpl
public static function create(
bool $exposeGlobalConstants = true,
Expand Down
7 changes: 3 additions & 4 deletions src/Console/Command/ChangeableDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Humbug\PhpScoper\Console\Command;

use Fidry\Console\Input\IO;
use Humbug\PhpScoper\NotInstantiable;
use InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -29,11 +30,9 @@
*/
final class ChangeableDirectory
{
private const WORKING_DIR_OPT = 'working-dir';
use NotInstantiable;

private function __construct()
{
}
private const WORKING_DIR_OPT = 'working-dir';

public static function createOption(): InputOption
{
Expand Down
25 changes: 25 additions & 0 deletions src/NotInstantiable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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.
*/

namespace Humbug\PhpScoper;

/**
* @private
*/
trait NotInstantiable
{
private function __construct()
{
}
}
7 changes: 3 additions & 4 deletions src/PhpParser/Node/FullyQualifiedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

namespace Humbug\PhpScoper\PhpParser\Node;

use Humbug\PhpScoper\NotInstantiable;
use InvalidArgumentException;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;

final class FullyQualifiedFactory
{
use NotInstantiable;

/**
* @param string|string[]|Name|null $name1
* @param string|string[]|Name|null $name2
Expand All @@ -32,8 +35,4 @@ public static function concat($name1, $name2, array $attributes = []): FullyQual

return FullyQualified::concat($name1, $name2, $attributes);
}

private function __construct()
{
}
}
7 changes: 3 additions & 4 deletions src/PhpParser/Node/NameFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

namespace Humbug\PhpScoper\PhpParser\Node;

use Humbug\PhpScoper\NotInstantiable;
use InvalidArgumentException;
use PhpParser\Node\Name;

final class NameFactory
{
use NotInstantiable;

/**
* @param string|string[]|Name|null $name1
* @param string|string[]|Name|null $name2
Expand All @@ -31,8 +34,4 @@ public static function concat($name1, $name2, array $attributes = []): Name

return Name::concat($name1, $name2, $attributes);
}

private function __construct()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Humbug\PhpScoper\PhpParser\NodeVisitor\NamespaceStmt;

use Humbug\PhpScoper\NotInstantiable;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\NodeVisitorAbstract;
Expand All @@ -23,6 +24,8 @@
*/
final class NamespaceManipulator extends NodeVisitorAbstract
{
use NotInstantiable;

private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';

public static function hasOriginalName(Namespace_ $namespace): bool
Expand All @@ -43,8 +46,4 @@ public static function setOriginalName(Namespace_ $namespace, ?Name $originalNam
{
$namespace->setAttribute(self::ORIGINAL_NAME_ATTRIBUTE, $originalName);
}

private function __construct()
{
}
}
7 changes: 3 additions & 4 deletions src/PhpParser/NodeVisitor/Resolver/OriginalNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

namespace Humbug\PhpScoper\PhpParser\NodeVisitor\Resolver;

use Humbug\PhpScoper\NotInstantiable;
use PhpParser\Node\Name;

final class OriginalNameResolver
{
use NotInstantiable;

private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';

public static function hasOriginalName(Name $namespace): bool
Expand All @@ -33,8 +36,4 @@ public static function getOriginalName(Name $name): Name

return $name->getAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
}

private function __construct()
{
}
}
7 changes: 3 additions & 4 deletions src/PhpParser/NodeVisitor/UseStmt/UseStmtManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Humbug\PhpScoper\PhpParser\NodeVisitor\UseStmt;

use Humbug\PhpScoper\NotInstantiable;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeVisitorAbstract;
Expand All @@ -23,6 +24,8 @@
*/
final class UseStmtManipulator extends NodeVisitorAbstract
{
use NotInstantiable;

private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';

public static function hasOriginalName(UseUse $use): bool
Expand All @@ -43,8 +46,4 @@ public static function setOriginalName(UseUse $use, ?Name $originalName): void
{
$use->setAttribute(self::ORIGINAL_NAME_ATTRIBUTE, $originalName);
}

private function __construct()
{
}
}

0 comments on commit 37d86c3

Please sign in to comment.