Skip to content

Commit 0dd385b

Browse files
authored
Merge pull request #22 from vossik/codestyle
Codestyle
2 parents 329ac2e + 90c7006 commit 0dd385b

31 files changed

Lines changed: 103 additions & 135 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=8.0",
1515
"infinityloop-dev/utils": "^2.1",
1616
"nette/utils": "^3.0",
17-
"nette/database": "^3.0",
17+
"nette/database": "^3.1",
1818
"nette/robot-loader": "^3.3",
1919
"symfony/console": "^5.2"
2020
},
@@ -32,7 +32,7 @@
3232
"mockery/mockery": "^1.4",
3333
"infection/infection": "^0.20",
3434
"phpstan/phpstan": "^0.12",
35-
"infinityloop-dev/coding-standard": "^0.1"
35+
"infinityloop-dev/coding-standard": "^0.2"
3636
},
3737
"autoload": {
3838
"psr-4": {

src/Attribute/ClassUniqueConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace CoolBeans\Attribute;
66

7-
#[\Attribute(\Attribute::TARGET_CLASS|\Attribute::IS_REPEATABLE)]
7+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
88
final class ClassUniqueConstraint
99
{
1010
public function __construct(
11-
public array $columns
11+
public array $columns,
1212
)
1313
{
1414
if (\count($columns) < 2) {

src/Attribute/DefaultValue.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
final class DefaultValue
99
{
1010
public function __construct(
11-
public string $defaultValue
12-
) {}
11+
public string $defaultValue,
12+
)
13+
{
14+
}
1315
}

src/Attribute/TypeOverride.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class TypeOverride
1111

1212
public function __construct(
1313
public string $type,
14-
int ...$lengthArgs
14+
int ...$lengthArgs,
1515
)
1616
{
1717
$this->lengthArgs = $lengthArgs;

src/Bean.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44

55
namespace CoolBeans;
66

7-
use \CoolBeans\Contract\PrimaryKey;
8-
97
abstract class Bean implements \CoolBeans\Contract\Row, \IteratorAggregate
108
{
119
use \Nette\SmartObject;
1210

13-
protected \Nette\Database\Table\ActiveRow $row;
1411
protected \ReflectionClass $reflection;
15-
protected PrimaryKey $primaryKey;
12+
protected \CoolBeans\Contract\PrimaryKey $primaryKey;
1613

17-
public function __construct(\Nette\Database\Table\ActiveRow $row)
14+
public function __construct(
15+
protected \Nette\Database\Table\ActiveRow $row,
16+
)
1817
{
19-
$this->row = $row;
2018
$this->reflection = new \ReflectionClass(static::class);
21-
$this->primaryKey = PrimaryKey::create($this->row);
19+
$this->primaryKey = \CoolBeans\Contract\PrimaryKey::create($this->row);
2220

2321
if (\CoolBeans\Config::$validateColumns) {
2422
$this->validateMissingColumns();
@@ -50,7 +48,7 @@ public function toArray() : array
5048
/**
5149
* Returns primary key object.
5250
*/
53-
public function getPrimaryKey() : PrimaryKey
51+
public function getPrimaryKey() : \CoolBeans\Contract\PrimaryKey
5452
{
5553
return $this->primaryKey;
5654
}
@@ -84,7 +82,7 @@ public function offsetExists($offset) : bool
8482
$property = $this->reflection->getProperty($offset);
8583

8684
return $property->isPublic();
87-
} catch (\ReflectionException $e) {
85+
} catch (\ReflectionException) {
8886
return false;
8987
}
9088
}

src/Bridge/Nette/DataSource.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace CoolBeans\Bridge\Nette;
66

7-
use \CoolBeans\Contract\PrimaryKey;
8-
97
interface DataSource extends \CoolBeans\Contract\DataSource
108
{
11-
public function getRow(PrimaryKey $key) : \CoolBeans\Bridge\Nette\ActiveRow;
9+
public function getRow(\CoolBeans\Contract\PrimaryKey $key) : \CoolBeans\Bridge\Nette\ActiveRow;
1210

1311
public function findAll() : \CoolBeans\Bridge\Nette\Selection;
1412

src/Bridge/Nette/Selection.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@
66

77
class Selection extends \Nette\Database\Table\Selection implements \CoolBeans\Contract\Selection
88
{
9+
public function where($condition, ...$params) : static
10+
{
11+
return parent::where($condition, ...$params);
12+
}
13+
14+
public function fetch() : ?\CoolBeans\Bridge\Nette\ActiveRow
15+
{
16+
return parent::fetch();
17+
}
18+
19+
public function key() : string|int
20+
{
21+
return parent::key();
22+
}
23+
924
public function getTableName() : string
1025
{
1126
return $this->getName();
1227
}
1328

1429
public function current() : ?\CoolBeans\Bridge\Nette\ActiveRow
1530
{
16-
return ($key = \current($this->keys)) !== false
17-
? $this->data[$key]
18-
: null;
31+
return parent::current()
32+
?: null;
1933
}
2034

2135
protected function createRow(array $row) : \CoolBeans\Bridge\Nette\ActiveRow

src/Bridge/Nette/TDecorator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace CoolBeans\Bridge\Nette;
66

7-
use \CoolBeans\Contract\PrimaryKey;
8-
97
trait TDecorator
108
{
119
use \CoolBeans\Decorator\TCommon;
1210

1311
protected \CoolBeans\Bridge\Nette\DataSource $dataSource;
1412

15-
public function getRow(PrimaryKey $key) : \CoolBeans\Bridge\Nette\ActiveRow
13+
public function getRow(\CoolBeans\Contract\PrimaryKey $key) : \CoolBeans\Bridge\Nette\ActiveRow
1614
{
1715
return $this->dataSource->getRow($key);
1816
}

src/Command/SqlGeneratorCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function configure() : void
2424

2525
protected function execute(
2626
\Symfony\Component\Console\Input\InputInterface $input,
27-
\Symfony\Component\Console\Output\OutputInterface $output
27+
\Symfony\Component\Console\Output\OutputInterface $output,
2828
) : int
2929
{
3030
$converted = '';
@@ -113,8 +113,7 @@ private function buildTable(array $data) : string
113113
. $row['name'] . \str_repeat(' ', $longestNameLength - $nameLength + 1)
114114
. $row['dataType'] . \str_repeat(' ', $longestDataTypeLength - $dataTypeLength + 1)
115115
. $row['notNull']
116-
. $row['default']
117-
);
116+
. $row['default']);
118117
}
119118

120119
return \implode(',' . \PHP_EOL, $toReturn);
@@ -315,7 +314,6 @@ private function getBeans(string $destination) : array
315314
throw new \CoolBeans\Exception\BeanWithoutPublicProperty('Bean ' . $bean->getShortName() . ' has no public property.');
316315
}
317316

318-
319317
$beans[] = $class;
320318
}
321319

src/Contract/ContextFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface ContextFactory
88
{
9-
public function create() : \Nette\Database\Context;
9+
public function create() : \Nette\Database\Explorer;
1010
}

0 commit comments

Comments
 (0)