Skip to content

Commit

Permalink
Merge pull request #8 from Big-Shark/analysis-XNA47y
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
Big-Shark committed Jan 26, 2016
2 parents 43e0fc0 + fcc4f20 commit a7843ba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/BuilderClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public function __construct($sql)
}

/**
* @return string
* @throws \Exception
*
* @return string
*/
public function convert()
{
Expand All @@ -58,7 +59,7 @@ public function convert()
}
}

usort($results, function($a, $b) {
usort($results, function ($a, $b) {
return (int) ('table' === $b['name']);
});

Expand Down
9 changes: 5 additions & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Generator

/**
* @param string $class
* @param array $args
* @param array $args
*/
public function __construct($class, $args = [])
{
Expand All @@ -25,7 +25,7 @@ public function __construct($class, $args = [])

/**
* @param string $name
* @param array $args
* @param array $args
*
* @return $this
*/
Expand Down Expand Up @@ -61,8 +61,9 @@ public function isStatic()
}

/**
* @return string
* @throws \Exception
*
* @return string
*/
public function generate()
{
Expand All @@ -81,7 +82,7 @@ public function generate()

$class = $this->class['name'];
$class .= count($this->class['args']) ? '('.implode(', ', $this->class['args']).')' : '';

$result = $class.($this->isStatic() ? '::' : '->').implode($parts, '->');

return $result;
Expand Down
65 changes: 32 additions & 33 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class ExampleTest extends \PHPUnit_Framework_TestCase
{

public function testNotCorrectSql()
{
try {
Expand All @@ -31,131 +30,131 @@ public function examples()
return [
[
'SELECT * FROM table',
'DB::table(\'table\')->get()'
'DB::table(\'table\')->get()',
],
[
'SELECT * FROM `table`',
'DB::table(\'table\')->get()'
'DB::table(\'table\')->get()',
],
[
'SELECT `*` FROM table',
'DB::table(\'table\')->get()'
'DB::table(\'table\')->get()',
],
[
'SELECT `*` FROM table t',
'DB::table(\'table AS t\')->get()'
'DB::table(\'table AS t\')->get()',
],
[
'SELECT a, b, c FROM table',
'DB::table(\'table\')->select(\'a\', \'b\', \'c\')->get()'
'DB::table(\'table\')->select(\'a\', \'b\', \'c\')->get()',
],
[
'SELECT `a`, `b`, `c` FROM table',
'DB::table(\'table\')->select(\'a\', \'b\', \'c\')->get()'
'DB::table(\'table\')->select(\'a\', \'b\', \'c\')->get()',
],
[
'SELECT * FROM table WHERE `a` = 1',
'DB::table(\'table\')->where(\'a\', \'=\', 1)->get()'
'DB::table(\'table\')->where(\'a\', \'=\', 1)->get()',
],
[
'SELECT * FROM table WHERE a = 1',
'DB::table(\'table\')->where(\'a\', \'=\', 1)->get()'
'DB::table(\'table\')->where(\'a\', \'=\', 1)->get()',
],
[
'SELECT * FROM `table` WHERE `a` = 1 and `b` = 1',
'DB::table(\'table\')->where(\'a\', \'=\', 1)->where(\'b\', \'=\', 1)->get()'
'DB::table(\'table\')->where(\'a\', \'=\', 1)->where(\'b\', \'=\', 1)->get()',
],
[
'SELECT * FROM `table` WHERE `a` = 1 or `b` = 1',
'DB::table(\'table\')->where(\'a\', \'=\', 1)->orWhere(\'b\', \'=\', 1)->get()'
'DB::table(\'table\')->where(\'a\', \'=\', 1)->orWhere(\'b\', \'=\', 1)->get()',
],
[
'SELECT * FROM `table` WHERE `a` = 1 and `b` = \'b\'',
'DB::table(\'table\')->where(\'a\', \'=\', 1)->where(\'b\', \'=\', \'b\')->get()'
'DB::table(\'table\')->where(\'a\', \'=\', 1)->where(\'b\', \'=\', \'b\')->get()',
],
[
'SELECT * FROM `table` WHERE `a` IN (\'a\', \'b\') or `b` IN (\'c\', \'d\')',
'DB::table(\'table\')->whereIn(\'a\', [\'a\', \'b\'])->orWhereIn(\'b\', [\'c\', \'d\'])->get()'
'DB::table(\'table\')->whereIn(\'a\', [\'a\', \'b\'])->orWhereIn(\'b\', [\'c\', \'d\'])->get()',
],
[
'SELECT * FROM `table` WHERE `a` NOT IN (\'a\', \'b\') or `b` NOT IN (\'c\', \'d\')',
'DB::table(\'table\')->whereNotIn(\'a\', [\'a\', \'b\'])->orWhereNotIn(\'b\', [\'c\', \'d\'])->get()'
'DB::table(\'table\')->whereNotIn(\'a\', [\'a\', \'b\'])->orWhereNotIn(\'b\', [\'c\', \'d\'])->get()',
],
[
'SELECT * FROM `table` WHERE `a` LIKE \'%a%\'',
'DB::table(\'table\')->where(\'a\', \'LIKE\', \'%a%\')->get()'
'DB::table(\'table\')->where(\'a\', \'LIKE\', \'%a%\')->get()',
],
[
'SELECT * FROM `table` WHERE `a` IS NULL and `b` IS NULL',
'DB::table(\'table\')->whereNull(\'a\')->whereNull(\'b\')->get()'
'DB::table(\'table\')->whereNull(\'a\')->whereNull(\'b\')->get()',
],
[
'SELECT * FROM `table` WHERE `a` IS NULL or `b` IS NULL',
'DB::table(\'table\')->whereNull(\'a\')->orWhereNull(\'b\')->get()'
'DB::table(\'table\')->whereNull(\'a\')->orWhereNull(\'b\')->get()',
],
[
'SELECT * FROM `table` WHERE `a` IS NOT NULL and `b` IS NOT NULL',
'DB::table(\'table\')->whereNotNull(\'a\')->whereNotNull(\'b\')->get()'
'DB::table(\'table\')->whereNotNull(\'a\')->whereNotNull(\'b\')->get()',
],
[
'SELECT * FROM `table` WHERE `a` IS NOT NULL or `b` IS NOT NULL',
'DB::table(\'table\')->whereNotNull(\'a\')->orWhereNotNull(\'b\')->get()'
'DB::table(\'table\')->whereNotNull(\'a\')->orWhereNotNull(\'b\')->get()',
],
[
'SELECT `a` as `b` FROM `table`',
'DB::table(\'table\')->select(\'a AS b\')->get()'
'DB::table(\'table\')->select(\'a AS b\')->get()',
],
[
'SELECT a as b FROM `table`',
'DB::table(\'table\')->select(\'a AS b\')->get()'
'DB::table(\'table\')->select(\'a AS b\')->get()',
],
[
'SELECT * FROM table LIMIT 10',
'DB::table(\'table\')->take(10)->get()'
'DB::table(\'table\')->take(10)->get()',
],
[
'SELECT * FROM `table` LIMIT 5, 10',
'DB::table(\'table\')->skip(5)->take(10)->get()'
'DB::table(\'table\')->skip(5)->take(10)->get()',
],
[
'SELECT * FROM table ORDER BY id',
'DB::table(\'table\')->orderBy(\'id\')->get()'
'DB::table(\'table\')->orderBy(\'id\')->get()',
],
[
'SELECT * FROM table ORDER BY id DESC',
'DB::table(\'table\')->orderBy(\'id\', \'DESC\')->get()'
'DB::table(\'table\')->orderBy(\'id\', \'DESC\')->get()',
],
[
'SELECT * FROM table GROUP BY id',
'DB::table(\'table\')->groupBy(\'id\')->get()'
'DB::table(\'table\')->groupBy(\'id\')->get()',
],
[
'SELECT * FROM table GROUP BY `id`',
'DB::table(\'table\')->groupBy(\'id\')->get()'
'DB::table(\'table\')->groupBy(\'id\')->get()',
],
[
'SELECT * FROM table LEFT JOIN `join_table` ON `table`.`id` = `join_table`.`table_id`',
'DB::table(\'table\')->leftJoin(\'join_table\', \'table.id\', \'=\', \'join_table.table_id\')->get()'
'DB::table(\'table\')->leftJoin(\'join_table\', \'table.id\', \'=\', \'join_table.table_id\')->get()',
],
[
'SELECT * FROM table RIGHT JOIN `join_table` ON `table`.`id` = `join_table`.`table_id`',
'DB::table(\'table\')->rightJoin(\'join_table\', \'table.id\', \'=\', \'join_table.table_id\')->get()'
'DB::table(\'table\')->rightJoin(\'join_table\', \'table.id\', \'=\', \'join_table.table_id\')->get()',
],
[
'SELECT * FROM table LEFT JOIN `join_table` `jt` ON `table`.`id` = `jt`.`table_id`',
'DB::table(\'table\')->leftJoin(\'join_table AS jt\', \'table.id\', \'=\', \'jt.table_id\')->get()'
'DB::table(\'table\')->leftJoin(\'join_table AS jt\', \'table.id\', \'=\', \'jt.table_id\')->get()',
],
[
'SELECT * FROM table LEFT JOIN `join_table` AS `jt` ON `table`.`id` = `jt`.`table_id`',
'DB::table(\'table\')->leftJoin(\'join_table AS jt\', \'table.id\', \'=\', \'jt.table_id\')->get()'
'DB::table(\'table\')->leftJoin(\'join_table AS jt\', \'table.id\', \'=\', \'jt.table_id\')->get()',
],
[
'SELECT count(`c`) FROM table',
'DB::table(\'table\')->select(DB::raw(\'COUNT(`c`)\'))->get()'
'DB::table(\'table\')->select(DB::raw(\'COUNT(`c`)\'))->get()',
],
[
'SELECT count(`c`) as c FROM table',
'DB::table(\'table\')->select(DB::raw(\'COUNT(`c`) AS c\'))->get()'
'DB::table(\'table\')->select(DB::raw(\'COUNT(`c`) AS c\'))->get()',
],
];
}
Expand Down

0 comments on commit a7843ba

Please sign in to comment.