Skip to content

Commit fe70028

Browse files
authored
Update README.md
1 parent 1cd9aa9 commit fe70028

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ $snippet = (new CodeSnippet())
3939
Use the `surroundingLines($first, $last)` method to select a range of "target" lines, which will be returned as the middle lines of the snippet:
4040

4141
```php
42-
use Permafrost\CodeSnippets\CodeSnippet;
43-
4442
$snippet = (new CodeSnippet())
4543
->surroundingLines(4, 7)
4644
->snippetLineCount(6)
@@ -50,37 +48,31 @@ $snippet = (new CodeSnippet())
5048
Use the `linesBefore()` and `linesAfter()` methods to specify the number of context lines to display before and after the "target" lines:
5149

5250
```php
53-
use Permafrost\CodeSnippets\CodeSnippet;
54-
5551
// the "target" line isn't displayed in the middle, but as the second line
5652
$snippet = (new CodeSnippet())
5753
->surroundingLine(4)
5854
->linesBefore(1)
5955
->linesAfter(3)
6056
->fromFile('/path/to/a/file.php');
6157
```
58+
6259
### Getting the snippet contents
6360

6461
The `getLines()` method returns an array of `SnippetLine` instances. The keys of the resulting array are the line numbers.
6562

66-
The `SnippetLine` instances may be cast to strings to display the value.
63+
The `SnippetLine` instances may be cast to strings to display the value. When working with `SnippetLine` instances, use `isSelected()` to determine if the line was selected using either the `surroundingLine()` or `surroundingLines()` method on the `CodeSnippet` instance.
6764

68-
```php
69-
use Permafrost\CodeSnippets\CodeSnippet;
65+
To get the value of a `SnippetLine`, use the `value()` method or cast the object to a string.
7066

71-
// the "target" line isn't displayed in the middle, but as the second line
67+
```php
7268
$snippet = (new CodeSnippet())
7369
->surroundingLine(4)
7470
->snippetLineCount(5)
7571
->fromFile('/path/to/a/file.php');
7672

7773
foreach($snippet->getLines() as $lineNum => $line) {
78-
// use ->isSelected() to determine if the line was selected using the
79-
// surroundingLine() or surroundingLines() method
8074
$prefix = $line->isSelected() ? ' * ' : ' ';
8175

82-
echo "{$prefix}{$line->lineNumber()} - {$line}" . PHP_EOL;
83-
// or
8476
echo $prefix . $line->lineNumber() . ' - ' . $line->value() . PHP_EOL;
8577
}
8678
```

0 commit comments

Comments
 (0)