File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ composer require permafrost-dev/code-snippets
2121
2222## Usage
2323
24+ ### Creating a snippet
25+
2426Use the ` surroundingLine($num) ` method to select the "target" line, which will be returned as the middle line of the snippet:
2527
2628``` php
@@ -55,6 +57,7 @@ $snippet = (new CodeSnippet())
5557 ->linesAfter(3)
5658 ->fromFile('/path/to/a/file.php');
5759```
60+ ### Getting the snippet contents
5861
5962The ` getLines() ` method returns an array of ` SnippetLine ` instances. The keys of the resulting array are the line numbers.
6063
@@ -80,6 +83,33 @@ foreach($snippet->getLines() as $lineNum => $line) {
8083}
8184```
8285
86+ ### Snippet line count
87+
88+ To determine the number of lines in the snippet, use the ` getSnippetLineCount() ` method:
89+
90+ ``` php
91+ $snippet = (new CodeSnippet())
92+ ->surroundingLines(4, 7)
93+ ->linesBefore(3)
94+ ->linesAfter(3)
95+ ->fromFile('/path/to/a/file.php');
96+
97+ echo "Snippet line count: " . $snippet->getSnippetLineCount() . PHP_EOL;
98+ ```
99+
100+ You can also use ` count() ` on the result of the ` getLines() ` method:
101+
102+ ``` php
103+ $snippet = (new CodeSnippet())
104+ ->surroundingLines(4, 7)
105+ ->linesBefore(3)
106+ ->linesAfter(3)
107+ ->fromFile('/path/to/a/file.php');
108+
109+ echo "Snippet line count: " . count($snippet->getLines()) . PHP_EOL;
110+ ```
111+
112+
83113## Testing
84114
85115``` bash
You can’t perform that action at this time.
0 commit comments