Skip to content

Commit b7755ae

Browse files
committed
Refactoring. Removed duplicate code.
Fixed documentation.
1 parent 1b2988f commit b7755ae

File tree

6 files changed

+1243
-1270
lines changed

6 files changed

+1243
-1270
lines changed

src/Component.php

Lines changed: 56 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,89 +10,71 @@
1010
*
1111
* @package SqlParser
1212
*/
13+
namespace SqlParser;
1314

14-
namespace {
15+
require_once 'common.php';
1516

16-
if (!function_exists('__')) {
17+
/**
18+
* A component (of a statement) is a part of a statement that is common to
19+
* multiple query types.
20+
*
21+
* @category Components
22+
* @package SqlParser
23+
* @author Dan Ungureanu <udan1107@gmail.com>
24+
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
25+
*/
26+
abstract class Component
27+
{
1728

18-
/**
19-
* Translates the given string.
20-
*
21-
* @param string $str String to be translated.
22-
*
23-
* @return string
24-
*/
25-
function __($str)
26-
{
27-
return $str;
28-
}
29+
/**
30+
* Parses the tokens contained in the given list in the context of the given
31+
* parser.
32+
*
33+
* @param Parser $parser The parser that serves as context.
34+
* @param TokensList $list The list of tokens that are being parsed.
35+
* @param array $options Parameters for parsing.
36+
*
37+
* @throws \Exception Not implemented yet.
38+
*
39+
* @return mixed
40+
*/
41+
public static function parse(
42+
Parser $parser, TokensList $list, array $options = array()
43+
) {
44+
// This method should be abstract, but it can't be both static and
45+
// abstract.
46+
throw new \Exception(\__('Not implemented yet.'));
2947
}
30-
}
31-
32-
namespace SqlParser {
3348

3449
/**
35-
* A component (of a statement) is a part of a statement that is common to
36-
* multiple query types.
50+
* Builds the string representation of a component of this type.
51+
*
52+
* In other words, this function represents the inverse function of
53+
* `static::parse`.
3754
*
38-
* @category Components
39-
* @package SqlParser
40-
* @author Dan Ungureanu <udan1107@gmail.com>
41-
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
55+
* @param mixed $component The component to be built.
56+
* @param array $options Parameters for building.
57+
*
58+
* @throws \Exception Not implemented yet.
59+
*
60+
* @return string
4261
*/
43-
abstract class Component
62+
public static function build($component, array $options = array())
4463
{
64+
// This method should be abstract, but it can't be both static and
65+
// abstract.
66+
throw new \Exception(\__('Not implemented yet.'));
67+
}
4568

46-
/**
47-
* Parses the tokens contained in the given list in the context of the given
48-
* parser.
49-
*
50-
* @param Parser $parser The parser that serves as context.
51-
* @param TokensList $list The list of tokens that are being parsed.
52-
* @param array $options Parameters for parsing.
53-
*
54-
* @throws \Exception Not implemented yet.
55-
*
56-
* @return mixed
57-
*/
58-
public static function parse(
59-
Parser $parser, TokensList $list, array $options = array()
60-
) {
61-
// This method should be abstract, but it can't be both static and
62-
// abstract.
63-
throw new \Exception(\__('Not implemented yet.'));
64-
}
65-
66-
/**
67-
* Builds the string representation of a component of this type.
68-
*
69-
* In other words, this function represents the inverse function of
70-
* `static::parse`.
71-
*
72-
* @param mixed $component The component to be built.
73-
* @param array $options Parameters for building.
74-
*
75-
* @throws \Exception Not implemented yet.
76-
*
77-
* @return string
78-
*/
79-
public static function build($component, array $options = array())
80-
{
81-
// This method should be abstract, but it can't be both static and
82-
// abstract.
83-
throw new \Exception(\__('Not implemented yet.'));
84-
}
85-
86-
/**
87-
* Builds the string representation of a component of this type.
88-
*
89-
* @see static::build
90-
*
91-
* @return string
92-
*/
93-
public function __toString()
94-
{
95-
return static::build($this);
96-
}
69+
/**
70+
* Builds the string representation of a component of this type.
71+
*
72+
* @see static::build
73+
*
74+
* @return string
75+
*/
76+
public function __toString()
77+
{
78+
return static::build($this);
9779
}
9880
}

0 commit comments

Comments
 (0)