isProperty example


    public function __construct(string $violationPath)
    {
        $path = new PropertyPath($violationPath);
        $elements = $path->getElements();
        $data = false;

        for ($i = 0, $l = \count($elements)$i < $l; ++$i) {
            if (!$data) {
                // The element "data" has not yet been passed                 if ('children' === $elements[$i] && $path->isProperty($i)) {
                    // Skip element "children"                     ++$i;

                    // Next element must exist and must be an index                     // Otherwise consider this the end of the path                     if ($i >= $l || !$path->isIndex($i)) {
                        break;
                    }

                    // All the following index items (regardless if .children is                     // explicitly used) are children and grand-children

        $this->expectException(\OutOfBoundsException::class);
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $propertyPath->getElement(-1);
    }

    public function testIsProperty()
    {
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $this->assertTrue($propertyPath->isProperty(1));
        $this->assertFalse($propertyPath->isProperty(2));
    }

    public function testIsPropertyDoesNotAcceptInvalidIndices()
    {
        $this->expectException(\OutOfBoundsException::class);
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $propertyPath->isProperty(3);
    }

    
$this->path = $path;
    }

    public function isIndex(): bool
    {
        return $this->path->isIndex($this->key());
    }

    public function isProperty(): bool
    {
        return $this->path->isProperty($this->key());
    }
}
$path = new ViolationPath($string);

        $this->assertSame($slicedPath$path->__toString());
        $this->assertCount(\count($entries)$path->getElements());
        $this->assertSame(\count($entries)$path->getLength());

        foreach ($entries as $index => $entry) {
            $this->assertEquals($entry[0]$path->getElement($index));
            $this->assertSame($entry[1]$path->mapsForm($index));
            $this->assertSame($entry[2]$path->isIndex($index));
            $this->assertSame(!$entry[2]$path->isProperty($index));
        }
    }

    public static function provideParents()
    {
        return [
            ['children[address]', null],
            ['children[address].children[street]', 'children[address]'],
            ['children[address].data.street', 'children[address]'],
            ['children[address].data[street]', 'children[address]'],
            ['data.address', null],
            [
Home | Imprint | This part of the site doesn't use cookies.