Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
}
],
"require": {
"php": ">=7.1",
"sofa/hookable": "dev-7.0.1-erasys as 7.0.1",
"illuminate/database": ">=5.5"
"php": "^8.2",
"sofa/hookable": "8.0.0",
"illuminate/support": "^10.0",
"illuminate/database": "^10.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "2.3.3",
"mockery/mockery": "^1.0",
"friendsofphp/php-cs-fixer": "^2.0"
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7",
"mockery/mockery": "^1.5",
"friendsofphp/php-cs-fixer": "^3.18.0"
},
"autoload": {
"psr-4": {
Expand All @@ -62,7 +63,7 @@
"minimum-stability": "stable",
"prefer_stable": true,
"scripts": {
"test": "phpunit && ./vendor/bin/phpcs src --standard=psr2 --report=diff --colors",
"test": "./vendor/bin/phpunit && ./vendor/bin/phpcs src --standard=psr2 --report=diff --colors",
"phpcs": "./vendor/bin/phpcs src --standard=psr2 --report=diff --colors"
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
Expand Down
30 changes: 15 additions & 15 deletions src/Eloquence.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This trait is an entry point for all the hooks that we want to apply
* on the Eloquent Model and Builder in order to let the magic happen.
*
* It also provides hasColumn and getColumnListing helper methods
* It also provides hasColumn and getColumnListing helper methods,
* so you can easily list or check columns in the model's table.
*
* @version 5.5
Expand Down Expand Up @@ -46,11 +46,11 @@ public static function bootEloquence()
/**
* Determine whether where should be treated as whereNull.
*
* @param string $method
* @param string $method
* @param ArgumentBag $args
* @return bool
*/
protected function isWhereNull($method, ArgumentBag $args)
protected function isWhereNull(string $method, ArgumentBag $args): bool
{
return $method === 'whereNull' || $method === 'where' && $this->isWhereNullByArgs($args);
}
Expand All @@ -70,14 +70,14 @@ protected function isWhereNullByArgs(ArgumentBag $args)
/**
* Extract real name and alias from the sql select clause.
*
* @param string $column
* @param string $column
* @return array
*/
protected function extractColumnAlias($column)
protected function extractColumnAlias(string $column): array
{
$alias = $column;

if (strpos($column, ' as ') !== false) {
if (strpos($column, ' as ')) {
list($column, $alias) = explode(' as ', $column);
}

Expand All @@ -87,10 +87,10 @@ protected function extractColumnAlias($column)
/**
* Get the target relation and column from the mapping.
*
* @param string $mapping
* @param string $mapping
* @return array
*/
public function parseMappedColumn($mapping)
public function parseMappedColumn(string $mapping): array
{
$segments = explode('.', $mapping);

Expand All @@ -104,10 +104,10 @@ public function parseMappedColumn($mapping)
/**
* Determine whether the key is meta attribute or actual table field.
*
* @param string $key
* @param string $key
* @return bool
*/
public static function hasColumn($key)
public static function hasColumn(string $key): bool
{
static::loadColumnListing();

Expand All @@ -119,7 +119,7 @@ public static function hasColumn($key)
*
* @return array
*/
public function getSearchableColumns()
public function getSearchableColumns(): array
{
return (property_exists($this, 'searchableColumns')) ? $this->searchableColumns : [];
}
Expand All @@ -129,7 +129,7 @@ public function getSearchableColumns()
*
* @return array
*/
public static function getColumnListing()
public static function getColumnListing(): array
{
static::loadColumnListing();

Expand All @@ -141,7 +141,7 @@ public static function getColumnListing()
*
* @return void
*/
protected static function loadColumnListing()
protected static function loadColumnListing(): void
{
if (empty(static::$columnListing)) {
$instance = new static;
Expand All @@ -158,7 +158,7 @@ protected static function loadColumnListing()
* @param QueryBuilder $query
* @return Builder
*/
public function newEloquentBuilder($query)
public function newEloquentBuilder(QueryBuilder $query): Builder
{
return new Builder($query);
}
Expand All @@ -168,7 +168,7 @@ public function newEloquentBuilder($query)
*
* @return QueryBuilder
*/
protected function newBaseQueryBuilder()
protected function newBaseQueryBuilder(): QueryBuilder
{
$conn = $this->getConnection();

Expand Down
10 changes: 5 additions & 5 deletions src/Searchable/ColumnCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getMappings()
* @param string $key
* @return bool
*/
public function offsetExists($key)
public function offsetExists($key) : bool
{
return array_key_exists($key, $this->columns);
}
Expand All @@ -112,7 +112,7 @@ public function offsetExists($key)
* @param string $key
* @return Column
*/
public function offsetGet($key)
public function offsetGet($key) : Column
{
return $this->columns[$key];
}
Expand All @@ -124,7 +124,7 @@ public function offsetGet($key)
* @param Column $column
* @return void
*/
public function offsetSet($key, $column)
public function offsetSet($key, $column) : void
{
$this->add($column);
}
Expand All @@ -135,7 +135,7 @@ public function offsetSet($key, $column)
* @param string $key
* @return Column
*/
public function offsetUnset($key)
public function offsetUnset($key) : void
{
unset($this->columns[$key]);
}
Expand All @@ -145,7 +145,7 @@ public function offsetUnset($key)
*
* @return ArrayIterator
*/
public function getIterator()
public function getIterator() : ArrayIterator
{
return new ArrayIterator($this->columns);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Subquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sofa\Eloquence;

use Illuminate\Database\Grammar;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function getQuery()
*
* @return string
*/
public function getValue()
public function getValue(Grammar $grammar)
{
$sql = '(' . $this->query->toSql() . ')';

Expand Down
1 change: 1 addition & 0 deletions tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function it_joins_relations_as_strings_or_array()
$builder->rightJoinRelations(['foo', 'bar']);
$builder->joinRelations('foo', 'bar');
$builder->joinRelations(['foo', 'bar']);
$this->assertEquals(1, 1);
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion tests/SearchableBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function it_moves_wheres_with_bindings_to_subquery_correctly()
})
->whereRaw('first_name = ?', ['outer_8'])
->whereDate('id', '=', ['inner_8'])
->where('last_name', new Expression('tkaczyk'));
->where('last_name', new Expression("tkaczyk"));

$query->get();

Expand Down
7 changes: 3 additions & 4 deletions tests/SubqueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ public function it_prints_as_aliased_query_in_parentheses()
$builder->method('getGrammar')->willReturn($grammar);
$builder->method('toSql')->willReturn('select * from "table" where id = ?');
$sub = new Subquery($builder);

$this->assertEquals('(select * from "table" where id = ?)', (string) $sub);


$this->assertEquals('select * from "table" where id = ?', (string) $sub->getQuery()->toSql());
$sub->setAlias('table_alias');

$this->assertEquals('(select * from "table" where id = ?) as "table_alias"', (string) $sub);
$this->assertEquals('(select * from "table" where id = ?) as "table_alias"', $sub->getValue($grammar));
$this->assertEquals('table_alias', $sub->getAlias());
}

Expand Down