Skip to content

Commit dcc0817

Browse files
author
Afonso Gloeden
committed
Indentation corrected (PSR-2)
1 parent 1e80ec2 commit dcc0817

File tree

10 files changed

+330
-192
lines changed

10 files changed

+330
-192
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/vendor/
1+
/vendor

Database/Query/SybaseGrammar.php

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
<?php namespace Uepg\LaravelSybase\Database\Query;
1+
<?php
2+
3+
namespace Uepg\LaravelSybase\Database\Query;
24

35
use Illuminate\Database\Query\Builder;
46
use Illuminate\Database\Query\Grammars\Grammar;
57

68
class SybaseGrammar extends Grammar {
7-
89
/**
910
* All of the available clause operators.
1011
*
1112
* @var array
1213
*/
13-
protected $operators = array(
14+
protected $operators = [
1415
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
1516
'like', 'not like', 'between', 'ilike',
1617
'&', '&=', '|', '|=', '^', '^=',
17-
);
18-
19-
protected $Builder;
20-
public function getBuilder(){
21-
return $this->Builder;
22-
}
23-
18+
];
19+
20+
protected $Builder;
2421

25-
/**
22+
public function getBuilder(){
23+
return $this->Builder;
24+
}
25+
26+
/**
2627
* Compile a select query into SQL.
2728
*
2829
* @param \Illuminate\Database\Query\Builder
2930
* @return string
3031
*/
31-
3232
public function compileSelect(Builder $query)
3333
{
34-
$this->Builder = $query;
34+
$this->Builder = $query;
3535
$components = $this->compileComponents($query);
3636

3737
return $this->concatenate($components);
3838
}
39+
3940
/**
4041
* Compile the "select *" portion of the query.
4142
*
@@ -45,19 +46,20 @@ public function compileSelect(Builder $query)
4546
*/
4647
protected function compileColumns(Builder $query, $columns)
4748
{
48-
if ( ! is_null($query->aggregate)) return;
49+
if (!is_null($query->aggregate)) {
50+
return;
51+
}
4952

5053
$select = $query->distinct ? 'select distinct ' : 'select ';
5154

5255
// If there is a limit on the query, but not an offset, we will add the top
5356
// clause to the query, which serves as a "limit" type clause within the
5457
// SQL Server system similar to the limit keywords available in MySQL.
55-
if ($query->limit > 0 && $query->offset <= 0)
56-
{
57-
$select .= 'top '.$query->limit.' ';
58+
if ($query->limit > 0 && $query->offset <= 0) {
59+
$select .= 'top ' . $query->limit . ' ';
5860
}
5961

60-
return $select.$this->columnize($columns);
62+
return $select . $this->columnize($columns);
6163
}
6264

6365
/**
@@ -71,16 +73,17 @@ protected function compileFrom(Builder $query, $table)
7173
{
7274
$from = parent::compileFrom($query, $table);
7375

74-
if (is_string($query->lock)) return $from.' '.$query->lock;
76+
if (is_string($query->lock)) {
77+
return $from . ' ' . $query->lock;
78+
}
7579

76-
if ( ! is_null($query->lock))
77-
{
78-
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
80+
if (!is_null($query->lock)) {
81+
return $from . ' with(rowlock,' . ($query->lock ? 'updlock,' : '') . 'holdlock)';
7982
}
8083

8184
return $from;
8285
}
83-
86+
8487
/**
8588
* Compile the "limit" portions of the query.
8689
*
@@ -113,7 +116,9 @@ protected function compileOffset(Builder $query, $offset)
113116
*/
114117
public function compileTruncate(Builder $query)
115118
{
116-
return array('truncate table '.$this->wrapTable($query->from) => array());
119+
return [
120+
'truncate table ' . $this->wrapTable($query->from) => array()
121+
];
117122
}
118123

119124
/**
@@ -134,9 +139,10 @@ public function getDateFormat()
134139
*/
135140
protected function wrapValue($value)
136141
{
137-
if ($value === '*') return $value;
142+
if ($value === '*') {
143+
return $value;
144+
}
138145

139-
return '['.str_replace(']', ']]', $value).']';
146+
return '[' . str_replace(']', ']]', $value) . ']';
140147
}
141-
142148
}

Database/Query/SybaseProcessor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
/*
4-
* To change this license header, choose License Headers in Project Properties.
5-
* To change this template file, choose Tools | Templates
6-
* and open the template in the editor.
7-
*/
3+
namespace Uepg\LaravelSybase\Database\Query;
84

5+
use Illuminate\Database\Query\Processors\Processor;
6+
7+
class SybaseConnector extends Processor
8+
{
9+
//
10+
}

Database/Schema/BlueprintSybase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class BlueprintSybase extends Blueprint
88
{
9-
public function numeric($column, $total=8, $autoIncrement=false)
9+
public function numeric($column, $total = 8, $autoIncrement = false)
1010
{
1111
return $this->addColumn('numeric', $column, compact('total', 'autoIncrement'));
1212
}
13-
}
13+
}

Database/Schema/SybaseGrammar.php

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@
77
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;
88

99
class SybaseGrammar extends Grammar {
10-
1110
/**
1211
* The possible column modifiers.
1312
*
1413
* @var array
1514
*/
16-
protected $modifiers = array('Increment', 'Nullable', 'Default');
15+
protected $modifiers = [
16+
'Increment',
17+
'Nullable',
18+
'Default'
19+
];
1720

1821
/**
1922
* The columns available as serials.
2023
*
2124
* @var array
2225
*/
23-
protected $serials = array('bigInteger', 'integer', 'numeric');
26+
protected $serials = [
27+
'bigInteger',
28+
'integer',
29+
'numeric'
30+
];
2431

2532
/**
2633
* Compile the query to determine if a table exists.
@@ -29,7 +36,7 @@ class SybaseGrammar extends Grammar {
2936
*/
3037
public function compileTableExists()
3138
{
32-
return "select * from sysobjects where type = 'U' and name = '?'";
39+
return "SELECT * FROM sysobjects WHERE type = 'U' AND name = '?'";
3340
}
3441

3542
/**
@@ -40,9 +47,18 @@ public function compileTableExists()
4047
*/
4148
public function compileColumnExists($table)
4249
{
43-
return "select col.name from sys.columns as col
44-
join sys.objects as obj on col.object_id = obj.object_id
45-
where obj.type = 'U' and obj.name = '$table'";
50+
return "
51+
SELECT
52+
col.name
53+
FROM
54+
sys.columns AS col
55+
JOIN
56+
sys.objects AS obj
57+
ON
58+
col.object_id = obj.object_id
59+
WHERE
60+
obj.type = 'U' AND
61+
obj.name = '$table'";
4662
}
4763

4864
/**
@@ -56,7 +72,9 @@ public function compileCreate(Blueprint $blueprint, Fluent $command)
5672
{
5773
$columns = implode(', ', $this->getColumns($blueprint));
5874

59-
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
75+
return 'CREATE TABLE ' . $this->wrapTable($blueprint) . " (
76+
$columns
77+
)";
6078
}
6179

6280
/**
@@ -72,7 +90,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
7290

7391
$columns = $this->getColumns($blueprint);
7492

75-
return 'alter table '.$table.' add '.implode(', ', $columns);
93+
return 'ALTER TABLE ' . $table . ' ADD ' . implode(', ', $columns);
7694
}
7795

7896
/**
@@ -88,7 +106,7 @@ public function compilePrimary(Blueprint $blueprint, Fluent $command)
88106

89107
$table = $this->wrapTable($blueprint);
90108

91-
return "alter table {$table} add constraint {$command->index} primary key ({$columns})";
109+
return "ALTER TABLE {$table} ADD CONSTRAINT {$command->index} PRIMARY KEY ({$columns})";
92110
}
93111

94112
/**
@@ -104,7 +122,7 @@ public function compileUnique(Blueprint $blueprint, Fluent $command)
104122

105123
$table = $this->wrapTable($blueprint);
106124

107-
return "create unique index {$command->index} on {$table} ({$columns})";
125+
return "CREATE UNIQUE INDEX {$command->index} ON {$table} ({$columns})";
108126
}
109127

110128
/**
@@ -120,7 +138,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
120138

121139
$table = $this->wrapTable($blueprint);
122140

123-
return "create index {$command->index} on {$table} ({$columns})";
141+
return "CREATE INDEX {$command->index} ON {$table} ({$columns})";
124142
}
125143

126144
/**
@@ -132,7 +150,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
132150
*/
133151
public function compileDrop(Blueprint $blueprint, Fluent $command)
134152
{
135-
return 'drop table '.$this->wrapTable($blueprint);
153+
return 'DROP TABLE ' . $this->wrapTable($blueprint);
136154
}
137155

138156
/**
@@ -144,7 +162,15 @@ public function compileDrop(Blueprint $blueprint, Fluent $command)
144162
*/
145163
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
146164
{
147-
return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \''.$blueprint->getTable().'\') drop table '.$blueprint->getTable();
165+
return "
166+
IF EXISTS (
167+
SELECT
168+
*
169+
FROM
170+
INFORMATION_SCHEMA.TABLES
171+
WHERE
172+
TABLE_NAME = '" . $blueprint->getTable() . "'
173+
) DROP TABLE " . $blueprint->getTable();
148174
}
149175

150176
/**
@@ -160,7 +186,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command)
160186

161187
$table = $this->wrapTable($blueprint);
162188

163-
return 'alter table '.$table.' drop column '.implode(', ', $columns);
189+
return 'ALTER TABLE ' . $table . ' DROP COLUMN ' . implode(', ', $columns);
164190
}
165191

166192
/**
@@ -174,7 +200,7 @@ public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
174200
{
175201
$table = $this->wrapTable($blueprint);
176202

177-
return "alter table {$table} drop constraint {$command->index}";
203+
return "ALTER TABLE {$table} DROP CONSTRAINT {$command->index}";
178204
}
179205

180206
/**
@@ -188,7 +214,7 @@ public function compileDropUnique(Blueprint $blueprint, Fluent $command)
188214
{
189215
$table = $this->wrapTable($blueprint);
190216

191-
return "drop index {$command->index} on {$table}";
217+
return "DROP INDEX {$command->index} ON {$table}";
192218
}
193219

194220
/**
@@ -202,7 +228,7 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command)
202228
{
203229
$table = $this->wrapTable($blueprint);
204230

205-
return "drop index {$command->index} on {$table}";
231+
return "DROP INDEX {$command->index} ON {$table}";
206232
}
207233

208234
/**
@@ -216,7 +242,7 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command)
216242
{
217243
$table = $this->wrapTable($blueprint);
218244

219-
return "alter table {$table} drop constraint {$command->index}";
245+
return "ALTER TABLE {$table} DROP CONSTRAINT {$command->index}";
220246
}
221247

222248
/**
@@ -230,7 +256,7 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
230256
{
231257
$from = $this->wrapTable($blueprint);
232258

233-
return "sp_rename {$from}, ".$this->wrapTable($command->to);
259+
return "sp_rename {$from}, " . $this->wrapTable($command->to);
234260
}
235261

236262
/**
@@ -542,9 +568,8 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
542568
*/
543569
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
544570
{
545-
if ( ! is_null($column->default))
546-
{
547-
return " default ".$this->getDefaultValue($column->default);
571+
if (!is_null($column->default)) {
572+
return " default " . $this->getDefaultValue($column->default);
548573
}
549574
}
550575

@@ -557,10 +582,8 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
557582
*/
558583
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
559584
{
560-
if (in_array($column->type, $this->serials) && $column->autoIncrement)
561-
{
585+
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
562586
return ' identity primary key';
563587
}
564588
}
565-
566589
}

0 commit comments

Comments
 (0)