Skip to content

Commit

Permalink
Removed Parser::getJsonPointer() and Parser::getJsonPointerPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
halaxa committed Feb 4, 2022
1 parent 1258fc5 commit 3302a16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 84 deletions.
14 changes: 6 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Nothing yet
## 1.0.0 - 2022-02-04
### Removed
- Removed deprecated functions `objects()` and `httpClientChunks()`.
- Removed deprecated `JsonMachine` entrypoint class.
- Removed deprecated `Decoder` interface.
- Removed deprecated `JsonMachine` entrypoint class. Use `Items` instead.
- Removed deprecated `Decoder` interface. Use `ItemDecoder` instead.
- Removed `Parser::getJsonPointer()`. Use `Parser::getJsonPointers()`/`Items::getJsonPointers()` instead.
- Removed `Parser::getJsonPointerPath()`. No replacement. Was not useful for anything other than testing and exposed internal implementation.

### Changed
#### Simplified and fixed decoding
Expand All @@ -40,10 +42,6 @@ They are not used anymore as described in previous point.
- `Lexer` renamed to `Tokens`
- `DebugLexer` renamed to `TokensWithDebugging`

### Deprecated
- `JsonMachine\Parser::getJsonPointer()`
- `JsonMachine\Parser::getJsonPointerPath()`

### Added
- Multiple JSON Pointers can be specified as an array in `pointer` option. See README. Thanks @fwolfsjaeger.
- New methods available during iteration: `Items::getCurrentJsonPointer()` and `Items::getMatchedJsonPointer()`
Expand Down Expand Up @@ -146,9 +144,9 @@ Alternative is to use `ExtJsonDecoder` which decodes items as objects by default
<?php

use JsonMachine\JsonDecoder\ExtJsonDecoder;
use JsonMachine\Items;
use JsonMachine\JsonMachine;

$jsonMachine = Items::fromFile('path/to.json', '', new ExtJsonDecoder);
$jsonMachine = JsonMachine::fromFile('path/to.json', '', new ExtJsonDecoder);
```
Therefore no additional casting is required.
- Invalid json object keys will now throw and won't be ignored anymore.
Expand Down
32 changes: 0 additions & 32 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,38 +338,6 @@ private function getMatchingJsonPointerPath(): array
return $this->paths[$matchingPointer];
}

/**
* @deprecated this method was revealing internal implementation and is not useful for anything anyway
*/
public function getJsonPointerPath()
{
@trigger_error(
'This method was revealing internal implementation and is not useful for anything anyway.',
E_USER_DEPRECATED
);

return reset($this->paths);
}

/**
* @deprecated use Parser::getJsonPointers() instead
*/
public function getJsonPointer()
{
@trigger_error(
'Since Parser now supports multiple JSON Pointers, use Parser::getJsonPointers() instead.',
E_USER_DEPRECATED
);

if ( ! $this->hasSingleJsonPointer) {
throw new JsonMachineException(
'This instance has multiple JSON Pointers. Call getJsonPointers() to access them.'
);
}

return reset($this->jsonPointers);
}

public function getJsonPointers(): array
{
return array_values($this->jsonPointers);
Expand Down
44 changes: 0 additions & 44 deletions test/JsonMachineTest/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,6 @@ public function data_testThrowsOnNotFoundJsonPointer()
];
}

/**
* @dataProvider data_testGetJsonPointerPath
*
* @param string $jsonPointer
*/
public function testGetJsonPointerPath($jsonPointer, array $expectedJsonPointerPath)
{
$parser = $this->createParser('{}', $jsonPointer);
$this->assertEquals($expectedJsonPointerPath, $parser->getJsonPointerPath());
}

public function data_testGetJsonPointerPath()
{
return [
['/', ['']],
['////', ['', '', '', '']],
['/apple', ['apple']],
['/apple/pie', ['apple', 'pie']],
['/0/1 ', [0, '1 ']],
];
}

/**
* @dataProvider data_testSyntaxError
*
Expand Down Expand Up @@ -439,28 +417,6 @@ public function testGetMatchedJsonPointerReturnsLiteralMatch()
}
}

public function testGetJsonPointer()
{
$parser = $this->createParser('{}', ['/one']);

$this->assertSame('/one', $parser->getJsonPointer());
}

public function testGetJsonPointerReturnsDefaultJsonPointer()
{
$parser = $this->createParser('{}');

$this->assertSame('', $parser->getJsonPointer());
}

public function testGetJsonPointerThrowsOnMultipleJsonPointers()
{
$this->expectException(JsonMachineException::class);
$this->expectExceptionMessage('getJsonPointers()');
$parser = $this->createParser('{}', ['/one', '/two']);
$parser->getJsonPointer();
}

public function testGetJsonPointers()
{
$parser = $this->createParser('{}', ['/one', '/two']);
Expand Down

0 comments on commit 3302a16

Please sign in to comment.