1<?php
2
3/**
4 * Retrieves code snippets for adding to test cases
5 *
6 */
7class gtCodeSnippet
8{
9
10  /**
11   * get the code snippet and initialise an array with it
12   *
13   * @param string $name
14   * @return array
15   */
16  public static function get($name) {
17
18    $filename = dirname(__FILE__) . '/codeSnippets/' . $name . '.txt';
19
20    if (!file_exists($filename)) {
21      throw new LogicException('The code snippet ' . $name . ' does not exist');
22    }
23
24    $lines = file($filename);
25    foreach($lines as $l) {
26      $array[] = rtrim($l);
27    }
28    return $array;
29  }
30
31
32  /**
33   * Append the code snippet on to an existing array
34   *
35   * @param string $name
36   * @param array $array
37   * @return array
38   */
39  public static function append($name, $array) {
40    $filename = dirname(__FILE__) . '/codeSnippets/' . $name . '.txt';
41
42    if (!file_exists($filename)) {
43      throw new LogicException('The code snippet ' . $name . ' does not exist');
44    }
45
46    $text =  file($filename);
47    foreach ($text as $t) {
48      $array[] = rtrim($t);
49    }
50
51    return $array;
52  }
53
54
55  /**
56   * Appends blank entries on to an array
57   *
58   * @param int $numberOfLines
59   * @param array $array
60   * @return array
61   */
62  public static function appendBlankLines($numberOfLines, $array) {
63
64    for ($i=0; $i< $numberOfLines; $i++) {
65      $array[] = "";
66    }
67
68    return $array;
69  }
70
71}
72?>