!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/laravel-crm/vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/   drwxrwxrwx
Free 13.15 GB of 57.97 GB (22.68%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     ReturnValueGenerator.php (7.45 KB)      -rw-rw-rw-
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\Framework\MockObject;

use function 
array_keys;
use function 
array_map;
use function 
explode;
use function 
in_array;
use function 
interface_exists;
use function 
sprintf;
use function 
str_contains;
use function 
str_ends_with;
use function 
str_starts_with;
use function 
substr;
use 
PHPUnit\Framework\MockObject\Generator\Generator;
use 
ReflectionClass;
use 
stdClass;
use 
Throwable;

/**
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
 *
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
 */
final class ReturnValueGenerator
{
    
/**
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     * @psalm-param class-string $stubClassName
     *
     * @throws Exception
     */
    
public function generate(string $classNamestring $methodNamestring $stubClassNamestring $returnType): mixed
    
{
        
$intersection false;
        
$union        false;

        if (
str_contains($returnType'|')) {
            
$types explode('|'$returnType);
            
$union true;

            foreach (
array_keys($types) as $key) {
                if (
str_starts_with($types[$key], '(') && str_ends_with($types[$key], ')')) {
                    
$types[$key] = substr($types[$key], 1, -1);
                }
            }
        } elseif (
str_contains($returnType'&')) {
            
$types        explode('&'$returnType);
            
$intersection true;
        } else {
            
$types = [$returnType];
        }

        if (!
$intersection) {
            
$lowerTypes array_map('strtolower'$types);

            if (
in_array(''$lowerTypestrue) ||
                
in_array('null'$lowerTypestrue) ||
                
in_array('mixed'$lowerTypestrue) ||
                
in_array('void'$lowerTypestrue)) {
                return 
null;
            }

            if (
in_array('true'$lowerTypestrue)) {
                return 
true;
            }

            if (
in_array('false'$lowerTypestrue) ||
                
in_array('bool'$lowerTypestrue)) {
                return 
false;
            }

            if (
in_array('float'$lowerTypestrue)) {
                return 
0.0;
            }

            if (
in_array('int'$lowerTypestrue)) {
                return 
0;
            }

            if (
in_array('string'$lowerTypestrue)) {
                return 
'';
            }

            if (
in_array('array'$lowerTypestrue)) {
                return [];
            }

            if (
in_array('static'$lowerTypestrue)) {
                return 
$this->newInstanceOf($stubClassName$className$methodName);
            }

            if (
in_array('object'$lowerTypestrue)) {
                return new 
stdClass;
            }

            if (
in_array('callable'$lowerTypestrue) ||
                
in_array('closure'$lowerTypestrue)) {
                return static function (): 
void
                
{
                };
            }

            if (
in_array('traversable'$lowerTypestrue) ||
                
in_array('generator'$lowerTypestrue) ||
                
in_array('iterable'$lowerTypestrue)) {
                
$generator = static function (): \Generator
                
{
                    yield from [];
                };

                return 
$generator();
            }

            if (!
$union) {
                return 
$this->testDoubleFor($returnType$className$methodName);
            }
        }

        if (
$union) {
            foreach (
$types as $type) {
                if (
str_contains($type'&')) {
                    
$_types explode('&'$type);

                    if (
$this->onlyInterfaces($_types)) {
                        return 
$this->testDoubleForIntersectionOfInterfaces($_types$className$methodName);
                    }
                }
            }
        }

        if (
$intersection && $this->onlyInterfaces($types)) {
            return 
$this->testDoubleForIntersectionOfInterfaces($types$className$methodName);
        }

        
$reason '';

        if (
$union) {
            
$reason ' because the declared return type is a union';
        } elseif (
$intersection) {
            
$reason ' because the declared return type is an intersection';
        }

        throw new 
RuntimeException(
            
sprintf(
                
'Return value for %s::%s() cannot be generated%s, please configure a return value for this method',
                
$className,
                
$methodName,
                
$reason,
            ),
        );
    }

    
/**
     * @psalm-param non-empty-list<string> $types
     */
    
private function onlyInterfaces(array $types): bool
    
{
        foreach (
$types as $type) {
            if (!
interface_exists($type)) {
                return 
false;
            }
        }

        return 
true;
    }

    
/**
     * @psalm-param class-string $stubClassName
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     *
     * @throws RuntimeException
     */
    
private function newInstanceOf(string $stubClassNamestring $classNamestring $methodName): Stub
    
{
        try {
            return (new 
ReflectionClass($stubClassName))->newInstanceWithoutConstructor();
            
// @codeCoverageIgnoreStart
        
} catch (Throwable $t) {
            throw new 
RuntimeException(
                
sprintf(
                    
'Return value for %s::%s() cannot be generated: %s',
                    
$className,
                    
$methodName,
                    
$t->getMessage(),
                ),
            );
            
// @codeCoverageIgnoreEnd
        
}
    }

    
/**
     * @psalm-param class-string $type
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     *
     * @throws RuntimeException
     */
    
private function testDoubleFor(string $typestring $classNamestring $methodName): Stub
    
{
        try {
            return (new 
Generator)->testDouble($typefalse, [], [], ''false);
            
// @codeCoverageIgnoreStart
        
} catch (Throwable $t) {
            throw new 
RuntimeException(
                
sprintf(
                    
'Return value for %s::%s() cannot be generated: %s',
                    
$className,
                    
$methodName,
                    
$t->getMessage(),
                ),
            );
            
// @codeCoverageIgnoreEnd
        
}
    }

    
/**
     * @psalm-param non-empty-list<string> $types
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     *
     * @throws RuntimeException
     */
    
private function testDoubleForIntersectionOfInterfaces(array $typesstring $classNamestring $methodName): Stub
    
{
        try {
            return (new 
Generator)->testDoubleForInterfaceIntersection($typesfalse);
            
// @codeCoverageIgnoreStart
        
} catch (Throwable $t) {
            throw new 
RuntimeException(
                
sprintf(
                    
'Return value for %s::%s() cannot be generated: %s',
                    
$className,
                    
$methodName,
                    
$t->getMessage(),
                ),
            );
            
// @codeCoverageIgnoreEnd
        
}
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0068 ]--