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
21
21
22
22
## Usage
23
23
24
+ ### Creating a snippet
25
+
24
26
Use the ` surroundingLine($num) ` method to select the "target" line, which will be returned as the middle line of the snippet:
25
27
26
28
``` php
@@ -55,6 +57,7 @@ $snippet = (new CodeSnippet())
55
57
->linesAfter(3)
56
58
->fromFile('/path/to/a/file.php');
57
59
```
60
+ ### Getting the snippet contents
58
61
59
62
The ` getLines() ` method returns an array of ` SnippetLine ` instances. The keys of the resulting array are the line numbers.
60
63
@@ -80,6 +83,33 @@ foreach($snippet->getLines() as $lineNum => $line) {
80
83
}
81
84
```
82
85
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
+
83
113
## Testing
84
114
85
115
``` bash
You can’t perform that action at this time.
0 commit comments