<?php
            
declare(strict_types=1);

namespace ExampleNamespace;

use Some\Classes\{
    ClassA,
    ClassB,
    ClassC as C
};

/**
 * Test
 */
class Example implements Iface1, Iface2, Iface3
{

    #[A1("param")]
    private ClassA|ClassB|null $unionType;

    /**
     * Test
     * @var ClassA&ClassB
     */
    private ClassA&ClassB $intersectionType;

    /**
     * Test
     * @param type $a
     * @param type $b
     */
    public function ifExample($a, $b)
    {
        if (convert($a) > $b) {
            echo "a is bigger than b";
        } elseif ($a == $b) {
            echo $a . " is equal to " . $b[0];
        } else {
            $result = getText($this->property1, $this->property2);
        }
        $result = $a < $b ? $a : $b;
    }

    /**
     * test
     */
    public function forExample()
    {
        for ($i = 1; $i <= 10; $i++) {
            echo 'Item: ';
            echo $i;
        }
    }

    /**
     * Test
     */
    public function foreachEample()
    {
        $arr = array(1, 2, 3, 4, "b" => 5, "a" => 6);
        foreach ($arr as &$value) {
            $value = (int) $value * 2;
        }
    }

    /**
     * Test
     */
    public function whileExample()
    {
        $i = 1;
        while ($i <= 10) {
            echo $i++;
        }
    }

    /**
     * Test
     * @param type $i
     */
    public function doWhileExample($i)
    {
        do {
            echo $i--;
        } while ($i > 0);
    }

    /**
     * Test
     */
    public function switchExample()
    {
        switch ($i) {
            case 0:
                echo "i equals 0";
                break;
            case 1:
                echo "i equals 1";
                break;
        }
    }

    /**
     * Test
     */
    public function matchExample()
    {
        $result = match ($i) {
            1, 2, 3 => "1, 2, or 3",
            4, 5, => "4 or 5",
            default => $this->getDefaultValue(),
        };
    }

    /**
     * Test
     * @return int
     */
    public function getDefaultValue(): int
    {
        return 10;
    }

    /**
     * Test
     */
    public function tryExample()
    {
        try {
            echo inverse(5) . "\n";
        } catch (Exception $e) {
            echo 'Caught exception: ' . $e->getMessage() . "\n";
        } finally {
            echo "Finally block";
        }
    }

    /**
     * Test
     * @param type $arg
     * @return \ExampleNamespace\#anon#ContentPHPSourceCode_php#1
     */
    public function anonymousClassExample($arg)
    {
        $instance = new class($arg) extends Anonymous
        {

            public function __construct($arg)
            {
                
            }

            public function anon()
            {
                echo "anonymous";
            }
        };
        return $instance;
    }

    /**
     * Test
     * @param type $arg1
     * @param type $arg2
     * @param type $arg3
     * @param type $arg4
     * @param type $arg5
     */
    public function alignParamsExample($arg1, $arg2, $arg3, $arg4, $arg5)
    {
        
    }

    /**
     * Test
     * @param Class1|Class2|null $object
     * @return int|float|null
     */
    public function unionTypesExample(Class1|Class2|null $object): int|float|null
    {
        return null;
    }

    /**
     * Test
     * @param ClassA&ClassB $object
     * @return ClassA&ClassB
     */
    public function intersectionTypesExample(ClassA&ClassB $object): ClassA&ClassB
    {
        return $object;
    }

    /**
     * Test
     * @param object $object
     */
    public function nullsafeOperatorExample(object $object)
    {
        $object?->nullsafe();
    }

}

enum EnumExample: string
{

    case FOO = 'F';
    case BAR = 'B';

    public function example(): string
    {
        return match ($this) {
            static::FOO => 'Foo',
            static::BAR => 'Bar',
        };
    }

}

$anonymousFunc = function ($arg) use ($param): int {
    return 1;
};

// Wrapping: Method Call Arguments must be set
(new Example())->alignParamsExample('one', 'two', 'three', 'four', 'five');

/**
 * Test
 * @param type $a
 * @param type $b
 */
function namedArguments($a, $b)
{
    
}

/**
 * ProcessMaker has made a number of its PHP functions available be used in triggers and conditions.
 * Most of these functions are wrappers for internal functions used in Gulliver, which is the development framework
 * used by ProcessMaker.
 * @class pmFunctions
 *
 * @name ProcessMaker Functions
 * @icon /images/pm.gif
 * @className class.pmFunctions.php
 */

/**
 * @method
 * 
 * Create a new user
 * 
 * @name PMFNewUser
 * @label PMF New User
 * 
 * @param string | $test
 * 
 * @return array | $response | Response
 */
function testAnnotation($test){
    return [];
}

namedArguments(a: 1, b: 2);

$shortName = 10;
$veryLooongName = 20;
$data = [
    'short_key' => 10,
    'very_looong_key' => 100,
];

