diff --git a/composer.json b/composer.json index 65a395da8..a73b0ae48 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "psr/http-message": "^1.0.1", "psr/http-server-middleware": "^1.0", "psr/event-dispatcher": "^0.7", + "psr/simple-cache": "^1.0", "fig/http-message-util": "^1.1.2", "nikic/fast-route": "^1.3", "nikic/php-parser": "^4.1", diff --git a/src/database/composer.json b/src/database/composer.json index 65a6d010b..19fdf8956 100644 --- a/src/database/composer.json +++ b/src/database/composer.json @@ -24,7 +24,8 @@ "friendsofphp/php-cs-fixer": "^2.9" }, "suggest": { - "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6)." + "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).", + "nikic/php-parser": "Required to use ModelCommand (^4.1)." }, "autoload": { "files": [ diff --git a/src/database/src/Commands/Ast/ModelUpdateVistor.php b/src/database/src/Commands/Ast/ModelUpdateVistor.php new file mode 100644 index 000000000..414538bfe --- /dev/null +++ b/src/database/src/Commands/Ast/ModelUpdateVistor.php @@ -0,0 +1,58 @@ +columns = $columns; + } + + public function leaveNode(Node $node) + { + switch ($node) { + case $node instanceof Node\Stmt\PropertyProperty: + if ('fillable' == $node->name) { + $node = $this->rewriteFillable($node); + } + + return $node; + case $node instanceof StaticPropertyFetch && $this->extends: + // Rewrite parent::$staticProperty to ParentClass::$staticProperty. + if ($node->class && 'parent' === $node->class->toString()) { + $node->class = new Name($this->extends->toCodeString()); + return $node; + } + } + } + + protected function rewriteFillable(Node\Stmt\PropertyProperty $node) + { + $items = []; + foreach ($this->columns as $column) { + $items[] = new Node\Expr\ArrayItem(new Node\Scalar\String_($column)); + } + + $node->default = new Node\Expr\Array_($items); + return $node; + } +} diff --git a/src/database/src/Commands/ModelCommand.php b/src/database/src/Commands/ModelCommand.php new file mode 100644 index 000000000..3a4cd049b --- /dev/null +++ b/src/database/src/Commands/ModelCommand.php @@ -0,0 +1,174 @@ +container = $container; + $this->factory = $container->get(PoolFactory::class); + + $parserFactory = new ParserFactory(); + $this->astParser = $parserFactory->create(ParserFactory::ONLY_PHP7); + $this->printer = new Standard(); + } + + protected function configure() + { + $this->addArgument('table', InputArgument::OPTIONAL, 'Which table you want create.') + ->addOption('pool', 'p', InputOption::VALUE_OPTIONAL, 'Which pool you want use.', 'default') + ->addOption('path', 'path', InputOption::VALUE_OPTIONAL, 'Which pool you want use.', 'app/Models'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->output = $output; + + $table = $input->getArgument('table'); + $pool = $input->getOption('pool'); + $path = $input->getOption('path'); + $path = BASE_PATH . '/' . $path; + if ($table) { + $this->createModel($table, $pool, $path); + } else { + $this->createModels($pool, $path); + } + } + + /** + * @return MySqlBuilder + */ + protected function getSchemaBuilder($poolName) + { + $pool = $this->factory->getDbPool($poolName); + /** @var Connection $connection */ + $connection = $pool->get()->getConnection(); + return $connection->getSchemaBuilder(); + } + + protected function createModels($pool, $path) + { + $builder = $this->getSchemaBuilder($pool); + $tables = []; + + foreach ($builder->getAllTables() as $row) { + $row = (array) $row; + $tables[] = reset($row); + } + + foreach ($tables as $table) { + $this->createModel($table, $pool, $path); + } + } + + protected function createModel($table, $poolName, $path) + { + $builder = $this->getSchemaBuilder($poolName); + + $columns = $builder->getColumnListing($table); + + $class = Str::studly($table); + $path = $path . '/' . $class . '.php'; + if (! file_exists($path)) { + $code = $this->getOriginCode($table); + file_put_contents($path, $code); + } + + $stms = $this->astParser->parse(file_get_contents($path)); + $traverser = new NodeTraverser(); + $traverser->addVisitor(new ModelUpdateVistor($columns)); + $stms = $traverser->traverse($stms); + $code = $this->printer->prettyPrintFile($stms); + + file_put_contents($path, $code); + $this->output->writeln(sprintf('Model %s is Created!', $class)); + } + + protected function getOriginCode($table) + { + $code = 'count(); - if ($countResults == 0) { + if (0 == $countResults) { break; } // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. - if ($callback($results, $page) === false) { + if (false === $callback($results, $page)) { return false; } unset($results); - $page++; + ++$page; } while ($countResults == $count); return true; @@ -58,15 +58,14 @@ trait BuildsQueries /** * Execute a callback over each item while chunking. * - * @param callable $callback - * @param int $count + * @param int $count * @return bool */ public function each(callable $callback, $count = 1000) { return $this->chunk($count, function ($results) use ($callback) { foreach ($results as $key => $value) { - if ($callback($value, $key) === false) { + if (false === $callback($value, $key)) { return false; } } @@ -76,7 +75,7 @@ trait BuildsQueries /** * Execute the query and get the first result. * - * @param array $columns + * @param array $columns * @return Model|object|static|null */ public function first($columns = ['*']) @@ -87,9 +86,8 @@ trait BuildsQueries /** * Apply the callback's query changes if the given "value" is true. * - * @param mixed $value - * @param callable $callback - * @param callable $default + * @param callable $callback + * @param callable $default * @return mixed|$this */ public function when($value, $callback, $default = null) @@ -106,7 +104,7 @@ trait BuildsQueries /** * Pass the query to a given callback. * - * @param \Closure $callback + * @param \Closure $callback * @return mixed|$this */ public function tap($callback) @@ -117,14 +115,13 @@ trait BuildsQueries /** * Apply the callback's query changes if the given "value" is false. * - * @param mixed $value - * @param callable $callback - * @param callable $default + * @param callable $callback + * @param callable $default * @return mixed|$this */ public function unless($value, $callback, $default = null) { - if (!$value) { + if (! $value) { return $callback($this, $value) ?: $this; } elseif ($default) { return $default($this, $value) ?: $this; diff --git a/src/database/src/Concerns/ManagesTransactions.php b/src/database/src/Concerns/ManagesTransactions.php index 62044a8d9..2102f644a 100644 --- a/src/database/src/Concerns/ManagesTransactions.php +++ b/src/database/src/Concerns/ManagesTransactions.php @@ -1,4 +1,5 @@ beginTransaction(); // We'll simply execute the given callback within a try / catch block and if we @@ -63,7 +63,7 @@ trait ManagesTransactions { $this->createTransaction(); - $this->transactions++; + ++$this->transactions; $this->fireConnectionEvent('beganTransaction'); } @@ -73,7 +73,7 @@ trait ManagesTransactions */ public function commit(): void { - if ($this->transactions == 1) { + if (1 == $this->transactions) { $this->getPdo()->commit(); } @@ -85,8 +85,7 @@ trait ManagesTransactions /** * Rollback the active database transaction. * - * @param int|null $toLevel - * @return void + * @param int|null $toLevel * * @throws \Exception */ @@ -119,8 +118,6 @@ trait ManagesTransactions /** * Get the number of active transactions. - * - * @return int */ public function transactionLevel(): int { @@ -130,10 +127,9 @@ trait ManagesTransactions /** * Handle an exception encountered when running a transacted statement. * - * @param \Exception $e - * @param int $currentAttempt - * @param int $maxAttempts - * @return void + * @param \Exception $e + * @param int $currentAttempt + * @param int $maxAttempts * * @throws \Exception */ @@ -144,7 +140,7 @@ trait ManagesTransactions // let the developer handle it in another way. We will decrement too. if ($this->causedByDeadlock($e) && $this->transactions > 1) { - $this->transactions--; + --$this->transactions; throw $e; } @@ -164,12 +160,10 @@ trait ManagesTransactions /** * Create a transaction within the database. - * - * @return void */ protected function createTransaction() { - if ($this->transactions == 0) { + if (0 == $this->transactions) { try { $this->getPdo()->beginTransaction(); } catch (Exception $e) { @@ -182,8 +176,6 @@ trait ManagesTransactions /** * Create a save point within the database. - * - * @return void */ protected function createSavepoint() { @@ -195,8 +187,7 @@ trait ManagesTransactions /** * Handle an exception from a transaction beginning. * - * @param \Throwable $e - * @return void + * @param \Throwable $e * * @throws \Exception */ @@ -214,12 +205,11 @@ trait ManagesTransactions /** * Perform a rollback within the database. * - * @param int $toLevel - * @return void + * @param int $toLevel */ protected function performRollBack($toLevel) { - if ($toLevel == 0) { + if (0 == $toLevel) { $this->getPdo()->rollBack(); } elseif ($this->queryGrammar->supportsSavepoints()) { $this->getPdo()->exec( diff --git a/src/database/src/Connection.php b/src/database/src/Connection.php index 1847a4f69..be0dbd3f6 100755 --- a/src/database/src/Connection.php +++ b/src/database/src/Connection.php @@ -1,4 +1,5 @@ queryGrammar = $this->getDefaultQueryGrammar(); } @@ -202,7 +201,7 @@ class Connection implements ConnectionInterface /** * Set the schema grammar to the default implementation. */ - public function useDefaultSchemaGrammar():void + public function useDefaultSchemaGrammar(): void { $this->schemaGrammar = $this->getDefaultSchemaGrammar(); } @@ -210,7 +209,7 @@ class Connection implements ConnectionInterface /** * Set the query post processor to the default implementation. */ - public function useDefaultPostProcessor():void + public function useDefaultPostProcessor(): void { $this->postProcessor = $this->getDefaultPostProcessor(); } @@ -250,7 +249,6 @@ class Connection implements ConnectionInterface /** * Run a select statement and return a single result. - * @return mixed */ public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true) { @@ -262,7 +260,7 @@ class Connection implements ConnectionInterface /** * Run a select statement against the database. */ - public function selectFromWriteConnection(string $query, array $bindings = []):array + public function selectFromWriteConnection(string $query, array $bindings = []): array { return $this->select($query, $bindings, false); } @@ -407,7 +405,7 @@ class Connection implements ConnectionInterface } $this->recordsHaveBeenModified( - $change = $this->getPdo()->exec($query) !== false + $change = false !== $this->getPdo()->exec($query) ); return $change; @@ -461,7 +459,7 @@ class Connection implements ConnectionInterface if ($value instanceof DateTimeInterface) { $bindings[$key] = $value->format($grammar->getDateFormat()); } elseif (is_bool($value)) { - $bindings[$key] = (int)$value; + $bindings[$key] = (int) $value; } } @@ -471,10 +469,9 @@ class Connection implements ConnectionInterface /** * Log a query in the connection's query log. * - * @param string $query - * @param array $bindings - * @param float|null $time - * @return void + * @param string $query + * @param array $bindings + * @param float|null $time */ public function logQuery($query, $bindings, $time = null) { @@ -488,7 +485,6 @@ class Connection implements ConnectionInterface /** * Reconnect to the database. * - * @return void * * @throws \LogicException */ @@ -503,8 +499,6 @@ class Connection implements ConnectionInterface /** * Disconnect from the underlying PDO connection. - * - * @return void */ public function disconnect() { @@ -513,9 +507,6 @@ class Connection implements ConnectionInterface /** * Register a database query listener with the connection. - * - * @param \Closure $callback - * @return void */ public function listen(Closure $callback) { @@ -526,9 +517,6 @@ class Connection implements ConnectionInterface /** * Get a new raw query expression. - * - * @param mixed $value - * @return \Hyperf\Database\Query\Expression */ public function raw($value): Expression { @@ -538,12 +526,11 @@ class Connection implements ConnectionInterface /** * Indicate if any records have been modified. * - * @param bool $value - * @return void + * @param bool $value */ public function recordsHaveBeenModified($value = true) { - if (!$this->recordsModified) { + if (! $this->recordsModified) { $this->recordsModified = $value; } } @@ -561,8 +548,8 @@ class Connection implements ConnectionInterface /** * Get a Doctrine Schema Column instance. * - * @param string $table - * @param string $column + * @param string $table + * @param string $column * @return \Doctrine\DBAL\Schema\Column */ public function getDoctrineColumn($table, $column) @@ -669,7 +656,6 @@ class Connection implements ConnectionInterface /** * Set the reconnect instance on the connection. * - * @param callable $reconnector * @return $this */ public function setReconnector(callable $reconnector) @@ -692,8 +678,7 @@ class Connection implements ConnectionInterface /** * Get an option from the configuration options. * - * @param string|null $option - * @return mixed + * @param string|null $option */ public function getConfig($option = null) { @@ -769,7 +754,6 @@ class Connection implements ConnectionInterface /** * Set the query post processor used by the connection. * - * @param \Hyperf\Database\Query\Processors\Processor $processor * @return $this */ public function setPostProcessor(Processor $processor) @@ -792,7 +776,6 @@ class Connection implements ConnectionInterface /** * Set the event dispatcher instance on the connection. * - * @param \Hyperf\Contracts\Events\Dispatcher $events * @return $this */ public function setEventDispatcher(Dispatcher $events) @@ -804,8 +787,6 @@ class Connection implements ConnectionInterface /** * Unset the event dispatcher for this connection. - * - * @return void */ public function unsetEventDispatcher() { @@ -819,7 +800,7 @@ class Connection implements ConnectionInterface */ public function pretending() { - return $this->pretending === true; + return true === $this->pretending; } /** @@ -834,8 +815,6 @@ class Connection implements ConnectionInterface /** * Clear the query log. - * - * @return void */ public function flushQueryLog() { @@ -844,8 +823,6 @@ class Connection implements ConnectionInterface /** * Enable the query log on the connection. - * - * @return void */ public function enableQueryLog() { @@ -854,8 +831,6 @@ class Connection implements ConnectionInterface /** * Disable the query log on the connection. - * - * @return void */ public function disableQueryLog() { @@ -936,9 +911,7 @@ class Connection implements ConnectionInterface /** * Register a connection resolver. * - * @param string $driver - * @param \Closure $callback - * @return void + * @param string $driver */ public static function resolverFor($driver, Closure $callback) { @@ -948,8 +921,7 @@ class Connection implements ConnectionInterface /** * Get the connection resolver for the given driver. * - * @param string $driver - * @return mixed + * @param string $driver */ public static function getResolver($driver) { @@ -963,7 +935,7 @@ class Connection implements ConnectionInterface */ protected function getDefaultQueryGrammar() { - return new QueryGrammar; + return new QueryGrammar(); } /** @@ -973,7 +945,6 @@ class Connection implements ConnectionInterface */ protected function getDefaultSchemaGrammar() { - // } /** @@ -983,13 +954,12 @@ class Connection implements ConnectionInterface */ protected function getDefaultPostProcessor() { - return new Processor; + return new Processor(); } /** * Configure the PDO prepared statement. * - * @param \PDOStatement $statement * @return \PDOStatement */ protected function prepared(PDOStatement $statement) @@ -1045,10 +1015,8 @@ class Connection implements ConnectionInterface /** * Run a SQL statement and log its execution context. * - * @param string $query - * @param array $bindings - * @param \Closure $callback - * @return mixed + * @param string $query + * @param array $bindings * @throws QueryException */ protected function run($query, $bindings, Closure $callback) @@ -1086,10 +1054,8 @@ class Connection implements ConnectionInterface /** * Run a SQL statement. * - * @param string $query - * @param array $bindings - * @param \Closure $callback - * @return mixed + * @param string $query + * @param array $bindings * @throws QueryException */ protected function runQueryCallback($query, $bindings, Closure $callback) @@ -1118,7 +1084,7 @@ class Connection implements ConnectionInterface /** * Get the elapsed time since a given starting point. * - * @param int $start + * @param int $start * @return float */ protected function getElapsedTime($start) @@ -1129,11 +1095,9 @@ class Connection implements ConnectionInterface /** * Handle a query exception. * - * @param \Exception $e - * @param string $query - * @param array $bindings - * @param \Closure $callback - * @return mixed + * @param \Exception $e + * @param string $query + * @param array $bindings * * @throws \Exception */ @@ -1154,11 +1118,8 @@ class Connection implements ConnectionInterface /** * Handle a query exception that occurred during query execution. * - * @param QueryException $e - * @param string $query - * @param array $bindings - * @param \Closure $callback - * @return mixed + * @param string $query + * @param array $bindings * @throws QueryException */ protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback) @@ -1174,8 +1135,6 @@ class Connection implements ConnectionInterface /** * Reconnect to the database if a PDO connection is missing. - * - * @return void */ protected function reconnectIfMissingConnection() { @@ -1187,12 +1146,12 @@ class Connection implements ConnectionInterface /** * Fire an event for this connection. * - * @param string $event + * @param string $event * @return array|null */ protected function fireConnectionEvent($event) { - if (!isset($this->events)) { + if (! isset($this->events)) { return; } @@ -1208,9 +1167,6 @@ class Connection implements ConnectionInterface /** * Fire the given event if possible. - * - * @param mixed $event - * @return void */ protected function event($event) { diff --git a/src/database/src/ConnectionInterface.php b/src/database/src/ConnectionInterface.php index ebb1edc49..0889cc57d 100755 --- a/src/database/src/ConnectionInterface.php +++ b/src/database/src/ConnectionInterface.php @@ -1,4 +1,5 @@ isPersistentConnection($options)) { + if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) { return new PDOConnection($dsn, $username, $password, $options); } @@ -135,11 +130,10 @@ class Connector /** * Handle an exception that occurred during connect execution. * - * @param \Throwable $e * @param string $dsn * @param string $username * @param string $password - * @param array $options + * @param array $options * @return \PDO * * @throws \Exception diff --git a/src/database/src/Connectors/ConnectorInterface.php b/src/database/src/Connectors/ConnectorInterface.php index 8822b3cdf..bd4e6f53d 100755 --- a/src/database/src/Connectors/ConnectorInterface.php +++ b/src/database/src/Connectors/ConnectorInterface.php @@ -1,4 +1,5 @@ createConnection($dsn, $config, $options); - if (!empty($config['database'])) { + if (! empty($config['database'])) { $connection->exec("use `{$config['database']}`;"); } @@ -51,13 +51,11 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Set the connection character set and collation. * - * @param \PDO $connection - * @param array $config - * @return void + * @param \PDO $connection */ protected function configureEncoding($connection, array $config) { - if (!isset($config['charset'])) { + if (! isset($config['charset'])) { return $connection; } @@ -69,7 +67,6 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Get the collation for the configuration. * - * @param array $config * @return string */ protected function getCollation(array $config) @@ -80,9 +77,7 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Set the timezone on the connection. * - * @param \PDO $connection - * @param array $config - * @return void + * @param \PDO $connection */ protected function configureTimezone($connection, array $config) { @@ -96,7 +91,6 @@ class MySqlConnector extends Connector implements ConnectorInterface * * Chooses socket or host/port based on the 'unix_socket' config value. * - * @param array $config * @return string */ protected function getDsn(array $config) @@ -109,18 +103,16 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Determine if the given configuration array has a UNIX socket value. * - * @param array $config * @return bool */ protected function hasSocket(array $config) { - return isset($config['unix_socket']) && !empty($config['unix_socket']); + return isset($config['unix_socket']) && ! empty($config['unix_socket']); } /** * Get the DSN string for a socket configuration. * - * @param array $config * @return string */ protected function getSocketDsn(array $config) @@ -131,7 +123,6 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Get the DSN string for a host / port configuration. * - * @param array $config * @return string */ protected function getHostDsn(array $config) @@ -147,10 +138,6 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Set the modes for the connection. - * - * @param \PDO $connection - * @param array $config - * @return void */ protected function setModes(PDO $connection, array $config) { @@ -167,10 +154,6 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Set the custom modes on the connection. - * - * @param \PDO $connection - * @param array $config - * @return void */ protected function setCustomModes(PDO $connection, array $config) { @@ -182,7 +165,6 @@ class MySqlConnector extends Connector implements ConnectorInterface /** * Get the query to enable strict mode. * - * @param \PDO $connection * @return string */ protected function strictMode(PDO $connection) diff --git a/src/database/src/DatabaseManager.php b/src/database/src/DatabaseManager.php index 0607756fc..c4f73803b 100755 --- a/src/database/src/DatabaseManager.php +++ b/src/database/src/DatabaseManager.php @@ -1,4 +1,5 @@ connections[$name])) { + if (! isset($this->connections[$name])) { $this->connections[$name] = $this->configure( $this->makeConnection($database), $type @@ -103,8 +101,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Disconnect from the given database and remove from local cache. * - * @param string $name - * @return void + * @param string $name */ public function purge($name = null) { @@ -118,8 +115,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Disconnect from the given database. * - * @param string $name - * @return void + * @param string $name */ public function disconnect($name = null) { @@ -131,14 +127,14 @@ class DatabaseManager implements ConnectionResolverInterface /** * Reconnect to the given database. * - * @param string $name + * @param string $name * @return \Hyperf\Database\Connection */ public function reconnect($name = null) { $this->disconnect($name = $name ?: $this->getDefaultConnection()); - if (!isset($this->connections[$name])) { + if (! isset($this->connections[$name])) { return $this->connection($name); } @@ -158,8 +154,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Set the default connection name. * - * @param string $name - * @return void + * @param string $name */ public function setDefaultConnection($name) { @@ -192,9 +187,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Register an extension connection resolver. * - * @param string $name - * @param callable $resolver - * @return void + * @param string $name */ public function extend($name, callable $resolver) { @@ -228,7 +221,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Make the database connection instance. * - * @param string $name + * @param string $name * @return \Hyperf\Database\Connection */ protected function makeConnection($name) @@ -280,7 +273,7 @@ class DatabaseManager implements ConnectionResolverInterface * Prepare the database connection instance. * * @param \Hyperf\Database\Connection $connection - * @param string $type + * @param string $type * @return \Hyperf\Database\Connection */ protected function configure(Connection $connection, $type) @@ -308,14 +301,14 @@ class DatabaseManager implements ConnectionResolverInterface * Prepare the read / write mode for database connection instance. * * @param \Hyperf\Database\Connection $connection - * @param string $type + * @param string $type * @return \Hyperf\Database\Connection */ protected function setPdoForType(Connection $connection, $type = null) { - if ($type === 'read') { + if ('read' === $type) { $connection->setPdo($connection->getReadPdo()); - } elseif ($type === 'write') { + } elseif ('write' === $type) { $connection->setReadPdo($connection->getPdo()); } @@ -325,7 +318,7 @@ class DatabaseManager implements ConnectionResolverInterface /** * Refresh the PDO connections on a given connection. * - * @param string $name + * @param string $name * @return \Hyperf\Database\Connection */ protected function refreshPdoConnections($name) diff --git a/src/database/src/DetectsDeadlocks.php b/src/database/src/DetectsDeadlocks.php index 5ef0cfa81..5ed5a211d 100644 --- a/src/database/src/DetectsDeadlocks.php +++ b/src/database/src/DetectsDeadlocks.php @@ -1,4 +1,5 @@ isExpression($table)) { + if (! $this->isExpression($table)) { return $this->wrap($this->tablePrefix . $table, true); } @@ -55,7 +55,7 @@ abstract class Grammar * Wrap a value in keyword identifiers. * * @param \Hyperf\Database\Query\Expression|string $value - * @param bool $prefixAlias + * @param bool $prefixAlias * @return string */ public function wrap($value, $prefixAlias = false) @@ -67,7 +67,7 @@ abstract class Grammar // If the value being wrapped has a column alias we will need to separate out // the pieces so we can wrap each of the segments of the expression on its // own, and then join these both back together using the "as" connector. - if (stripos($value, ' as ') !== false) { + if (false !== stripos($value, ' as ')) { return $this->wrapAliasedValue($value, $prefixAlias); } @@ -77,7 +77,6 @@ abstract class Grammar /** * Convert an array of column names into a delimited string. * - * @param array $columns * @return string */ public function columnize(array $columns) @@ -88,7 +87,6 @@ abstract class Grammar /** * Create query parameter place-holders for an array. * - * @param array $values * @return string */ public function parameterize(array $values) @@ -99,7 +97,6 @@ abstract class Grammar /** * Get the appropriate query parameter place-holder for a value. * - * @param mixed $value * @return string */ public function parameter($value) @@ -125,7 +122,6 @@ abstract class Grammar /** * Determine if the given value is a raw expression. * - * @param mixed $value * @return bool */ public function isExpression($value) @@ -181,7 +177,7 @@ abstract class Grammar * Wrap a value that has an alias. * * @param string $value - * @param bool $prefixAlias + * @param bool $prefixAlias * @return string */ protected function wrapAliasedValue($value, $prefixAlias = false) @@ -205,13 +201,13 @@ abstract class Grammar /** * Wrap the given value segments. * - * @param array $segments + * @param array $segments * @return string */ protected function wrapSegments($segments) { return collect($segments)->map(function ($segment, $key) use ($segments) { - return $key == 0 && count($segments) > 1 + return 0 == $key && count($segments) > 1 ? $this->wrapTable($segment) : $this->wrapValue($segment); })->implode('.'); @@ -225,7 +221,7 @@ abstract class Grammar */ protected function wrapValue($value) { - if ($value !== '*') { + if ('*' !== $value) { return '"' . str_replace('"', '""', $value) . '"'; } diff --git a/src/database/src/Model/Builder.php b/src/database/src/Model/Builder.php index 4068aa973..c48574e9b 100755 --- a/src/database/src/Model/Builder.php +++ b/src/database/src/Model/Builder.php @@ -1,4 +1,5 @@ localMacros[$parameters[0]] = $parameters[1]; return; @@ -151,21 +148,20 @@ class Builder /** * Dynamically handle calls into the query instance. * - * @param string $method - * @param array $parameters - * @return mixed + * @param string $method + * @param array $parameters * * @throws \BadMethodCallException */ public static function __callStatic($method, $parameters) { - if ($method === 'macro') { + if ('macro' === $method) { static::$macros[$parameters[0]] = $parameters[1]; return; } - if (!isset(static::$macros[$method])) { + if (! isset(static::$macros[$method])) { static::throwBadMethodCallException($method); } @@ -178,8 +174,6 @@ class Builder /** * Force a clone of the underlying query builder when cloning. - * - * @return void */ public function __clone() { @@ -189,7 +183,6 @@ class Builder /** * Create and return an un-saved model instance. * - * @param array $attributes * @return \Hyperf\Database\Model\Model */ public function make(array $attributes = []) @@ -200,7 +193,7 @@ class Builder /** * Register a new global scope. * - * @param string $identifier + * @param string $identifier * @param \Hyperf\Database\Model\Scope|\Closure $scope * @return $this */ @@ -223,7 +216,7 @@ class Builder */ public function withoutGlobalScope($scope) { - if (!is_string($scope)) { + if (! is_string($scope)) { $scope = get_class($scope); } @@ -237,12 +230,11 @@ class Builder /** * Remove all or passed registered global scopes. * - * @param array|null $scopes * @return $this */ public function withoutGlobalScopes(array $scopes = null) { - if (!is_array($scopes)) { + if (! is_array($scopes)) { $scopes = array_keys($this->scopes); } @@ -266,7 +258,6 @@ class Builder /** * Add a where clause on the primary key to the query. * - * @param mixed $id * @return $this */ public function whereKey($id) @@ -283,7 +274,6 @@ class Builder /** * Add a where clause on the primary key to the query. * - * @param mixed $id * @return $this */ public function whereKeyNot($id) @@ -301,9 +291,7 @@ class Builder * Add a basic where clause to the query. * * @param string|array|\Closure $column - * @param mixed $operator - * @param mixed $value - * @param string $boolean + * @param string $boolean * @return $this */ public function where($column, $operator = null, $value = null, $boolean = 'and') @@ -322,9 +310,7 @@ class Builder /** * Add an "or where" clause to the query. * - * @param \Closure|array|string $column - * @param mixed $operator - * @param mixed $value + * @param \Closure|array|string $column * @return \Hyperf\Database\Model\Builder|static */ public function orWhere($column, $operator = null, $value = null) @@ -332,7 +318,7 @@ class Builder [$value, $operator] = $this->query->prepareValueAndOperator( $value, $operator, - func_num_args() === 2 + 2 === func_num_args() ); return $this->where($column, $operator, $value, 'or'); @@ -375,7 +361,6 @@ class Builder /** * Create a collection of models from plain arrays. * - * @param array $items * @return \Hyperf\Database\Model\Collection */ public function hydrate(array $items) @@ -390,8 +375,8 @@ class Builder /** * Create a collection of models from a raw query. * - * @param string $query - * @param array $bindings + * @param string $query + * @param array $bindings * @return \Hyperf\Database\Model\Collection */ public function fromQuery($query, $bindings = []) @@ -404,8 +389,7 @@ class Builder /** * Find a model by its primary key. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|static[]|static|null */ public function find($id, $columns = ['*']) @@ -421,7 +405,7 @@ class Builder * Find multiple models by their primary keys. * * @param \Hyperf\Contracts\Support\Arrayable|array $ids - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection */ public function findMany($ids, $columns = ['*']) @@ -436,8 +420,7 @@ class Builder /** * Find a model by its primary key or throw an exception. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|static|static[] * * @throws \Hyperf\Database\Model\ModelNotFoundException @@ -450,11 +433,11 @@ class Builder if (count($result) === count(array_unique($id))) { return $result; } - } elseif (!is_null($result)) { + } elseif (! is_null($result)) { return $result; } - throw (new ModelNotFoundException)->setModel( + throw (new ModelNotFoundException())->setModel( get_class($this->model), $id ); @@ -463,13 +446,12 @@ class Builder /** * Find a model by its primary key or return fresh model instance. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|static */ public function findOrNew($id, $columns = ['*']) { - if (!is_null($model = $this->find($id, $columns))) { + if (! is_null($model = $this->find($id, $columns))) { return $model; } @@ -479,13 +461,11 @@ class Builder /** * Get the first record matching the attributes or instantiate it. * - * @param array $attributes - * @param array $values * @return \Hyperf\Database\Model\Model|static */ public function firstOrNew(array $attributes, array $values = []) { - if (!is_null($instance = $this->where($attributes)->first())) { + if (! is_null($instance = $this->where($attributes)->first())) { return $instance; } @@ -495,13 +475,11 @@ class Builder /** * Get the first record matching the attributes or create it. * - * @param array $attributes - * @param array $values * @return \Hyperf\Database\Model\Model|static */ public function firstOrCreate(array $attributes, array $values = []) { - if (!is_null($instance = $this->where($attributes)->first())) { + if (! is_null($instance = $this->where($attributes)->first())) { return $instance; } @@ -513,8 +491,6 @@ class Builder /** * Create or update a record matching the attributes, and fill it with values. * - * @param array $attributes - * @param array $values * @return \Hyperf\Database\Model\Model|static */ public function updateOrCreate(array $attributes, array $values = []) @@ -527,25 +503,24 @@ class Builder /** * Execute the query and get the first result or throw an exception. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|static * * @throws \Hyperf\Database\Model\ModelNotFoundException */ public function firstOrFail($columns = ['*']) { - if (!is_null($model = $this->first($columns))) { + if (! is_null($model = $this->first($columns))) { return $model; } - throw (new ModelNotFoundException)->setModel(get_class($this->model)); + throw (new ModelNotFoundException())->setModel(get_class($this->model)); } /** * Execute the query and get the first result or call a callback. * - * @param \Closure|array $columns - * @param \Closure|null $callback + * @param \Closure|array $columns * @return \Hyperf\Database\Model\Model|static|mixed */ public function firstOr($columns = ['*'], Closure $callback = null) @@ -556,7 +531,7 @@ class Builder $columns = ['*']; } - if (!is_null($model = $this->first($columns))) { + if (! is_null($model = $this->first($columns))) { return $model; } @@ -566,8 +541,7 @@ class Builder /** * Get a single column's value from the first result of a query. * - * @param string $column - * @return mixed + * @param string $column */ public function value($column) { @@ -579,7 +553,7 @@ class Builder /** * Execute the query as a "select" statement. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection|static[] */ public function get($columns = ['*']) @@ -599,7 +573,7 @@ class Builder /** * Get the hydrated models without eager loading. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model[]|static[] */ public function getModels($columns = ['*']) @@ -612,7 +586,6 @@ class Builder /** * Eager load the relationships for the models. * - * @param array $models * @return array */ public function eagerLoadRelations(array $models) @@ -621,7 +594,7 @@ class Builder // For nested eager loads we'll skip loading them here and they will be set as an // eager load on the query to retrieve the relation so that they will be eager // loaded on that query, because that is where they get hydrated as models. - if (strpos($name, '.') === false) { + if (false === strpos($name, '.')) { $models = $this->eagerLoadRelation($models, $name, $constraints); } } @@ -632,7 +605,7 @@ class Builder /** * Get the relation instance for the given relation name. * - * @param string $name + * @param string $name * @return \Hyperf\Database\Model\Relations\Relation */ public function getRelation($name) @@ -675,8 +648,7 @@ class Builder /** * Chunk the results of a query by comparing numeric IDs. * - * @param int $count - * @param callable $callback + * @param int $count * @param string|null $column * @param string|null $alias * @return bool @@ -699,14 +671,14 @@ class Builder $countResults = $results->count(); - if ($countResults == 0) { + if (0 == $countResults) { break; } // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. - if ($callback($results) === false) { + if (false === $callback($results)) { return false; } @@ -721,8 +693,8 @@ class Builder /** * Get an array with the values of a given column. * - * @param string $column - * @param string|null $key + * @param string $column + * @param string|null $key * @return \Hyperf\Utils\Collection */ public function pluck($column, $key = null) @@ -732,9 +704,9 @@ class Builder // If the model has a mutator for the requested column, we will spin through // the results and mutate the values so that the mutated version of these // columns are returned as you would expect from these Model models. - if (!$this->model->hasGetMutator($column) && - !$this->model->hasCast($column) && - !in_array($column, $this->model->getDates())) { + if (! $this->model->hasGetMutator($column) && + ! $this->model->hasCast($column) && + ! in_array($column, $this->model->getDates())) { return $results; } @@ -746,10 +718,10 @@ class Builder /** * Paginate the given query. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page * @return \Hyperf\Contracts\Pagination\LengthAwarePaginator * * @throws \InvalidArgumentException @@ -773,10 +745,10 @@ class Builder /** * Paginate the given query into a simple paginator. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page * @return \Hyperf\Contracts\Pagination\Paginator */ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) @@ -799,7 +771,6 @@ class Builder /** * Save a new model and return the instance. * - * @param array $attributes * @return \Hyperf\Database\Model\Model|$this */ public function create(array $attributes = []) @@ -812,7 +783,6 @@ class Builder /** * Save a new model and return the instance. Allow mass-assignment. * - * @param array $attributes * @return \Hyperf\Database\Model\Model|$this */ public function forceCreate(array $attributes) @@ -825,7 +795,6 @@ class Builder /** * Update a record in the database. * - * @param array $values * @return int */ public function update(array $values) @@ -836,9 +805,8 @@ class Builder /** * Increment a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ public function increment($column, $amount = 1, array $extra = []) @@ -853,9 +821,8 @@ class Builder /** * Decrement a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ public function decrement($column, $amount = 1, array $extra = []) @@ -869,8 +836,6 @@ class Builder /** * Delete a record from the database. - * - * @return mixed */ public function delete() { @@ -885,8 +850,6 @@ class Builder * Run the default delete function on the builder. * * Since we do not apply scopes here, the row will actually be deleted. - * - * @return mixed */ public function forceDelete() { @@ -895,9 +858,6 @@ class Builder /** * Register a replacement for the default delete function. - * - * @param \Closure $callback - * @return void */ public function onDelete(Closure $callback) { @@ -906,9 +866,6 @@ class Builder /** * Call the given local model scopes. - * - * @param array $scopes - * @return mixed */ public function scopes(array $scopes) { @@ -927,7 +884,7 @@ class Builder // messed up when adding scopes. Then we'll return back out the builder. $builder = $builder->callScope( [$this->model, 'scope' . ucfirst($scope)], - (array)$parameters + (array) $parameters ); } @@ -941,14 +898,14 @@ class Builder */ public function applyScopes() { - if (!$this->scopes) { + if (! $this->scopes) { return $this; } $builder = clone $this; foreach ($this->scopes as $identifier => $scope) { - if (!isset($builder->scopes[$identifier])) { + if (! isset($builder->scopes[$identifier])) { continue; } @@ -975,7 +932,6 @@ class Builder /** * Set the relationships that should be eager loaded. * - * @param mixed $relations * @return $this */ public function with($relations) @@ -990,7 +946,6 @@ class Builder /** * Prevent the specified relations from being eager loaded. * - * @param mixed $relations * @return $this */ public function without($relations) @@ -1005,7 +960,7 @@ class Builder /** * Create a new instance of the model being queried. * - * @param array $attributes + * @param array $attributes * @return \Hyperf\Database\Model\Model|static */ public function newModelInstance($attributes = []) @@ -1061,7 +1016,6 @@ class Builder /** * Set the relationships being eagerly loaded. * - * @param array $eagerLoad * @return $this */ public function setEagerLoads(array $eagerLoad) @@ -1110,7 +1064,7 @@ class Builder /** * Get the given macro by name. * - * @param string $name + * @param string $name * @return \Closure */ public function getMacro($name) @@ -1121,9 +1075,7 @@ class Builder /** * Eagerly load the relationship on a set of models. * - * @param array $models * @param string $name - * @param \Closure $constraints * @return array */ protected function eagerLoadRelation(array $models, $name, Closure $constraints) @@ -1183,8 +1135,6 @@ class Builder /** * Add a generic "order by" clause if the query doesn't already have one. - * - * @return void */ protected function enforceOrderBy() { @@ -1196,12 +1146,11 @@ class Builder /** * Add the "updated at" column to an array of values. * - * @param array $values * @return array */ protected function addUpdatedAtColumn(array $values) { - if (!$this->model->usesTimestamps()) { + if (! $this->model->usesTimestamps()) { return $values; } @@ -1216,9 +1165,7 @@ class Builder /** * Apply the given scope on the current builder instance. * - * @param callable $scope - * @param array $parameters - * @return mixed + * @param array $parameters */ protected function callScope(callable $scope, $parameters = []) { @@ -1234,7 +1181,7 @@ class Builder $result = $scope(...array_values($parameters)) ?? $this; - if (count((array)$query->wheres) > $originalWhereCount) { + if (count((array) $query->wheres) > $originalWhereCount) { $this->addNewWheresWithinGroup($query, $originalWhereCount); } @@ -1244,9 +1191,7 @@ class Builder /** * Nest where conditions by slicing them at the given where count. * - * @param \Hyperf\Database\Query\Builder $query - * @param int $originalWhereCount - * @return void + * @param int $originalWhereCount */ protected function addNewWheresWithinGroup(QueryBuilder $query, $originalWhereCount) { @@ -1271,9 +1216,7 @@ class Builder /** * Slice where conditions at the given offset and add them to the query as a nested condition. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $whereSlice - * @return void + * @param array $whereSlice */ protected function groupWhereSliceForScope(QueryBuilder $query, $whereSlice) { @@ -1295,7 +1238,7 @@ class Builder /** * Create a where array with nested where conditions. * - * @param array $whereSlice + * @param array $whereSlice * @param string $boolean * @return array */ @@ -1311,7 +1254,6 @@ class Builder /** * Parse a list of relations into individuals. * - * @param array $relations * @return array */ protected function parseWithRelations(array $relations) @@ -1328,7 +1270,6 @@ class Builder [$name, $constraints] = Str::contains($name, ':') ? $this->createSelectWithConstraint($name) : [$name, function () { - // }]; } @@ -1360,7 +1301,7 @@ class Builder * Parse the nested relationships in a relation. * * @param string $name - * @param array $results + * @param array $results * @return array */ protected function addNestedWiths($name, $results) @@ -1373,9 +1314,8 @@ class Builder foreach (explode('.', $name) as $segment) { $progress[] = $segment; - if (!isset($results[$last = implode('.', $progress)])) { + if (! isset($results[$last = implode('.', $progress)])) { $results[$last] = function () { - // }; } } diff --git a/src/database/src/Model/Collection.php b/src/database/src/Model/Collection.php index fa33bd3f0..41e697fcc 100755 --- a/src/database/src/Model/Collection.php +++ b/src/database/src/Model/Collection.php @@ -1,4 +1,5 @@ isEmpty()) { - return new static; + return new static(); } return $this->whereIn($this->first()->getKeyName(), $key); @@ -142,7 +141,7 @@ class Collection extends BaseCollection * Load a set of relationships onto the mixed relationship collection. * * @param string $relation - * @param array $relations + * @param array $relations * @return $this */ public function loadMorph($relation, $relations) @@ -166,7 +165,6 @@ class Collection extends BaseCollection /** * Add an item to the collection. * - * @param mixed $item * @return $this */ public function add($item) @@ -178,11 +176,6 @@ class Collection extends BaseCollection /** * Determine if a key exists in the collection. - * - * @param mixed $key - * @param mixed $operator - * @param mixed $value - * @return bool */ public function contains($key, $operator = null, $value = null): bool { @@ -232,15 +225,13 @@ class Collection extends BaseCollection /** * Run a map over each of the items. - * - * @param callable $callback */ public function map(callable $callback): BaseCollection { $result = parent::map($callback); return $result->contains(function ($item) { - return !$item instanceof Model; + return ! $item instanceof Model; }) ? $result->toBase() : $result; } @@ -253,7 +244,7 @@ class Collection extends BaseCollection public function fresh($with = []) { if ($this->isEmpty()) { - return new static; + return new static(); } $model = $this->first(); @@ -278,12 +269,12 @@ class Collection extends BaseCollection */ public function diff($items): BaseCollection { - $diff = new static; + $diff = new static(); $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { - if (!isset($dictionary[$item->getKey()])) { + if (! isset($dictionary[$item->getKey()])) { $diff->add($item); } } @@ -299,7 +290,7 @@ class Collection extends BaseCollection */ public function intersect($items): BaseCollection { - $intersect = new static; + $intersect = new static(); $dictionary = $this->getDictionary($items); @@ -315,12 +306,11 @@ class Collection extends BaseCollection /** * Return only unique items from the collection. * - * @param string|callable|null $key - * @param bool $strict + * @param string|callable|null $key */ public function unique($key = null, bool $strict = false): BaseCollection { - if (!is_null($key)) { + if (! is_null($key)) { return parent::unique($key, $strict); } @@ -330,7 +320,6 @@ class Collection extends BaseCollection /** * Returns only the models from the collection with the specified keys. * - * @param mixed $keys * @return static */ public function only($keys): BaseCollection @@ -347,7 +336,6 @@ class Collection extends BaseCollection /** * Returns all models in the collection except the models with specified keys. * - * @param mixed $keys * @return static */ public function except($keys): BaseCollection @@ -405,8 +393,7 @@ class Collection extends BaseCollection /** * Get an array with the values of a given key. * - * @param string $value - * @param string|null $key + * @param string $value */ public function pluck($value, ?string $key = null): BaseCollection { @@ -415,7 +402,6 @@ class Collection extends BaseCollection /** * Get the keys of the collection items. - * */ public function keys(): BaseCollection { @@ -425,7 +411,7 @@ class Collection extends BaseCollection /** * Zip the collection together with one or more arrays. * - * @param mixed ...$items + * @param mixed ...$items */ public function zip($items): BaseCollection { @@ -434,7 +420,6 @@ class Collection extends BaseCollection /** * Collapse the collection of items into a single array. - * */ public function collapse(): BaseCollection { @@ -451,7 +436,6 @@ class Collection extends BaseCollection /** * Flip the items in the collection. - * */ public function flip(): BaseCollection { @@ -543,9 +527,7 @@ class Collection extends BaseCollection /** * Load a relationship path if it is not already eager loaded. * - * @param \Hyperf\Database\Model\Collection $models - * @param array $path - * @return void + * @param \Hyperf\Database\Model\Collection $models */ protected function loadMissingRelation(Collection $models, array $path) { @@ -558,7 +540,7 @@ class Collection extends BaseCollection } $models->filter(function ($model) use ($name) { - return !is_null($model) && !$model->relationLoaded($name); + return ! is_null($model) && ! $model->relationLoaded($name); })->load($relation); if (empty($path)) { diff --git a/src/database/src/Model/Concerns/GuardsAttributes.php b/src/database/src/Model/Concerns/GuardsAttributes.php index f1198c542..2f9035666 100644 --- a/src/database/src/Model/Concerns/GuardsAttributes.php +++ b/src/database/src/Model/Concerns/GuardsAttributes.php @@ -1,4 +1,5 @@ getFillable()) === 0 && $this->getGuarded() == ['*']; + return 0 === count($this->getFillable()) && $this->getGuarded() == ['*']; } /** * Get the fillable attributes of a given array. * - * @param array $attributes * @return array */ protected function fillableFromArray(array $attributes) diff --git a/src/database/src/Model/Concerns/HasAttributes.php b/src/database/src/Model/Concerns/HasAttributes.php index a48ec04aa..e33df96ac 100644 --- a/src/database/src/Model/Concerns/HasAttributes.php +++ b/src/database/src/Model/Concerns/HasAttributes.php @@ -1,4 +1,5 @@ serializeDate($attributes[$key]); } @@ -840,7 +820,6 @@ trait HasAttributes /** * Get an attribute array of all arrayable values. * - * @param array $values * @return array */ protected function getArrayableItems(array $values) @@ -859,8 +838,7 @@ trait HasAttributes /** * Get an attribute from the $attributes array. * - * @param string $key - * @return mixed + * @param string $key */ protected function getAttributeFromArray($key) { @@ -872,8 +850,7 @@ trait HasAttributes /** * Get a relationship value from a method. * - * @param string $method - * @return mixed + * @param string $method * * @throws \LogicException */ @@ -897,21 +874,17 @@ trait HasAttributes /** * Get the value of an attribute using its mutator. * - * @param string $key - * @param mixed $value - * @return mixed + * @param string $key */ protected function mutateAttribute($key, $value) { - return $this->{'get'.Str::studly($key).'Attribute'}($value); + return $this->{'get' . Str::studly($key) . 'Attribute'}($value); } /** * Get the value of an attribute using its mutator for array conversion. * - * @param string $key - * @param mixed $value - * @return mixed + * @param string $key */ protected function mutateAttributeForArray($key, $value) { @@ -923,9 +896,7 @@ trait HasAttributes /** * Cast an attribute to a native PHP type. * - * @param string $key - * @param mixed $value - * @return mixed + * @param string $key */ protected function castAttribute($key, $value) { @@ -970,7 +941,7 @@ trait HasAttributes /** * Get the type of cast for a model attribute. * - * @param string $key + * @param string $key * @return string */ protected function getCastType($key) @@ -989,42 +960,40 @@ trait HasAttributes /** * Determine if the cast type is a custom date time cast. * - * @param string $cast + * @param string $cast * @return bool */ protected function isCustomDateTimeCast($cast) { - return strncmp($cast, 'date:', 5) === 0 || - strncmp($cast, 'datetime:', 9) === 0; + return 0 === strncmp($cast, 'date:', 5) || + 0 === strncmp($cast, 'datetime:', 9); } /** * Determine if the cast type is a decimal cast. * - * @param string $cast + * @param string $cast * @return bool */ protected function isDecimalCast($cast) { - return strncmp($cast, 'decimal:', 8) === 0; + return 0 === strncmp($cast, 'decimal:', 8); } /** * Set the value of an attribute using its mutator. * - * @param string $key - * @param mixed $value - * @return mixed + * @param string $key */ protected function setMutatedAttributeValue($key, $value) { - return $this->{'set'.Str::studly($key).'Attribute'}($value); + return $this->{'set' . Str::studly($key) . 'Attribute'}($value); } /** * Determine if the given attribute is a date or date castable. * - * @param string $key + * @param string $key * @return bool */ protected function isDateAttribute($key) @@ -1036,9 +1005,8 @@ trait HasAttributes /** * Get an array attribute with the given key and value set. * - * @param string $path - * @param string $key - * @param mixed $value + * @param string $path + * @param string $key * @return $this */ protected function getArrayAttributeWithValue($path, $key, $value) @@ -1051,7 +1019,7 @@ trait HasAttributes /** * Get an array attribute or return an empty array if it is not set. * - * @param string $key + * @param string $key * @return array */ protected function getArrayAttributeByKey($key) @@ -1063,15 +1031,14 @@ trait HasAttributes /** * Cast the given attribute to JSON. * - * @param string $key - * @param mixed $value + * @param string $key * @return string */ protected function castAttributeAsJson($key, $value) { $value = $this->asJson($value); - if ($value === false) { + if (false === $value) { throw JsonEncodingException::forAttribute( $this, $key, @@ -1085,7 +1052,6 @@ trait HasAttributes /** * Encode the given value as JSON. * - * @param mixed $value * @return string */ protected function asJson($value) @@ -1097,7 +1063,7 @@ trait HasAttributes * Return a decimal as string. * * @param float $value - * @param int $decimals + * @param int $decimals * @return string */ protected function asDecimal($value, $decimals) @@ -1108,7 +1074,6 @@ trait HasAttributes /** * Return a timestamp as DateTime object with time set to 00:00:00. * - * @param mixed $value * @return \Hyperf\Utils\Carbon */ protected function asDate($value) @@ -1119,7 +1084,6 @@ trait HasAttributes /** * Return a timestamp as DateTime object. * - * @param mixed $value * @return \Hyperf\Utils\Carbon */ protected function asDateTime($value) @@ -1167,7 +1131,7 @@ trait HasAttributes /** * Determine if the given value is a standard date format. * - * @param string $value + * @param string $value * @return bool */ protected function isStandardDateFormat($value) @@ -1178,7 +1142,6 @@ trait HasAttributes /** * Return a timestamp as unix timestamp. * - * @param mixed $value * @return int */ protected function asTimestamp($value) @@ -1189,7 +1152,6 @@ trait HasAttributes /** * Prepare a date for array / JSON serialization. * - * @param \DateTimeInterface $date * @return string */ protected function serializeDate(DateTimeInterface $date) @@ -1200,7 +1162,7 @@ trait HasAttributes /** * Determine whether a value is Date / DateTime castable for inbound manipulation. * - * @param string $key + * @param string $key * @return bool */ protected function isDateCastable($key) @@ -1211,7 +1173,7 @@ trait HasAttributes /** * Determine whether a value is JSON castable for inbound manipulation. * - * @param string $key + * @param string $key * @return bool */ protected function isJsonCastable($key) @@ -1222,8 +1184,8 @@ trait HasAttributes /** * Determine if the given attributes were changed. * - * @param array $changes - * @param array|string|null $attributes + * @param array $changes + * @param array|string|null $attributes * @return bool */ protected function hasChanges($changes, $attributes = null) @@ -1250,7 +1212,6 @@ trait HasAttributes /** * Get all of the attribute mutator methods. * - * @param mixed $class * @return array */ protected static function getMutatorMethods($class) diff --git a/src/database/src/Model/Concerns/HasEvents.php b/src/database/src/Model/Concerns/HasEvents.php index 1b6d0dcb5..7dd2591a3 100644 --- a/src/database/src/Model/Concerns/HasEvents.php +++ b/src/database/src/Model/Concerns/HasEvents.php @@ -1,4 +1,5 @@ getEventDispatcher(); - if (!$dispatcher instanceof EventDispatcherInterface) { + if (! $dispatcher instanceof EventDispatcherInterface) { return true; } @@ -59,45 +56,42 @@ trait HasEvents $this->fireCustomModelEvent($event, 'dispatch') ); - if ($result === false) { + if (false === $result) { return false; } $eventName = 'Hyperf\\Database\\Model\\Events\\' . Str::studly($event); - return !empty($result) ? $result : $dispatcher->dispatch(new $eventName($this, $event)); + return ! empty($result) ? $result : $dispatcher->dispatch(new $eventName($this, $event)); } /** * Fire a custom model event for the given event. * - * @param string $event - * @param string $method + * @param string $event + * @param string $method * @return mixed|null */ protected function fireCustomModelEvent($event, $method) { - if (!isset($this->dispatchesEvents[$event])) { + if (! isset($this->dispatchesEvents[$event])) { return; } $result = $this->getEventDispatcher()->$method(new $this->dispatchesEvents[$event]($this)); - if (!is_null($result)) { + if (! is_null($result)) { return $result; } } /** * Filter the model event results. - * - * @param mixed $result - * @return mixed */ protected function filterModelEventResults($result) { if (is_array($result)) { $result = array_filter($result, function ($response) { - return !is_null($response); + return ! is_null($response); }); } diff --git a/src/database/src/Model/Concerns/HasGlobalScopes.php b/src/database/src/Model/Concerns/HasGlobalScopes.php index 8f1240baf..a8d421e6c 100644 --- a/src/database/src/Model/Concerns/HasGlobalScopes.php +++ b/src/database/src/Model/Concerns/HasGlobalScopes.php @@ -1,4 +1,5 @@ getKeyName(); - return $this->newHasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey); + return $this->newHasOne($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey); } /** * Define a has-one-through relationship. * - * @param string $related - * @param string $through - * @param string|null $firstKey - * @param string|null $secondKey - * @param string|null $localKey - * @param string|null $secondLocalKey + * @param string $related + * @param string $through + * @param string|null $firstKey + * @param string|null $secondKey + * @param string|null $localKey + * @param string|null $secondLocalKey * @return \Hyperf\Database\Model\Relations\HasOneThrough */ public function hasOneThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null) { - $through = new $through; + $through = new $through(); $firstKey = $firstKey ?: $this->getForeignKey(); @@ -105,11 +106,11 @@ trait HasRelationships /** * Define a polymorphic one-to-one relationship. * - * @param string $related - * @param string $name - * @param string $type - * @param string $id - * @param string $localKey + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey * @return \Hyperf\Database\Model\Relations\MorphOne */ public function morphOne($related, $name, $type = null, $id = null, $localKey = null) @@ -122,16 +123,16 @@ trait HasRelationships $localKey = $localKey ?: $this->getKeyName(); - return $this->newMorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); + return $this->newMorphOne($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey); } /** * Define an inverse one-to-one or many relationship. * - * @param string $related - * @param string $foreignKey - * @param string $ownerKey - * @param string $relation + * @param string $related + * @param string $foreignKey + * @param string $ownerKey + * @param string $relation * @return \Hyperf\Database\Model\Relations\BelongsTo */ public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null) @@ -149,7 +150,7 @@ trait HasRelationships // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. if (is_null($foreignKey)) { - $foreignKey = Str::snake($relation).'_'.$instance->getKeyName(); + $foreignKey = Str::snake($relation) . '_' . $instance->getKeyName(); } // Once we have the foreign key names, we'll just create a new Model query @@ -169,10 +170,10 @@ trait HasRelationships /** * Define a polymorphic, inverse one-to-one or many relationship. * - * @param string $name - * @param string $type - * @param string $id - * @param string $ownerKey + * @param string $name + * @param string $type + * @param string $id + * @param string $ownerKey * @return \Hyperf\Database\Model\Relations\MorphTo */ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null) @@ -199,7 +200,7 @@ trait HasRelationships /** * Retrieve the actual class name for a given morph class. * - * @param string $class + * @param string $class * @return string */ public static function getActualClassNameForMorph($class) @@ -210,9 +211,9 @@ trait HasRelationships /** * Define a one-to-many relationship. * - * @param string $related - * @param string $foreignKey - * @param string $localKey + * @param string $related + * @param string $foreignKey + * @param string $localKey * @return \Hyperf\Database\Model\Relations\HasMany */ public function hasMany($related, $foreignKey = null, $localKey = null) @@ -226,7 +227,7 @@ trait HasRelationships return $this->newHasMany( $instance->newQuery(), $this, - $instance->getTable().'.'.$foreignKey, + $instance->getTable() . '.' . $foreignKey, $localKey ); } @@ -234,17 +235,17 @@ trait HasRelationships /** * Define a has-many-through relationship. * - * @param string $related - * @param string $through - * @param string|null $firstKey - * @param string|null $secondKey - * @param string|null $localKey - * @param string|null $secondLocalKey + * @param string $related + * @param string $through + * @param string|null $firstKey + * @param string|null $secondKey + * @param string|null $localKey + * @param string|null $secondLocalKey * @return \Hyperf\Database\Model\Relations\HasManyThrough */ public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null) { - $through = new $through; + $through = new $through(); $firstKey = $firstKey ?: $this->getForeignKey(); @@ -264,11 +265,11 @@ trait HasRelationships /** * Define a polymorphic one-to-many relationship. * - * @param string $related - * @param string $name - * @param string $type - * @param string $id - * @param string $localKey + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey * @return \Hyperf\Database\Model\Relations\MorphMany */ public function morphMany($related, $name, $type = null, $id = null, $localKey = null) @@ -284,19 +285,19 @@ trait HasRelationships $localKey = $localKey ?: $this->getKeyName(); - return $this->newMorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); + return $this->newMorphMany($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey); } /** * Define a many-to-many relationship. * - * @param string $related - * @param string $table - * @param string $foreignPivotKey - * @param string $relatedPivotKey - * @param string $parentKey - * @param string $relatedKey - * @param string $relation + * @param string $related + * @param string $table + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey + * @param string $relatedKey + * @param string $relation * @return \Hyperf\Database\Model\Relations\BelongsToMany */ public function belongsToMany( @@ -346,14 +347,14 @@ trait HasRelationships /** * Define a polymorphic many-to-many relationship. * - * @param string $related - * @param string $name - * @param string $table - * @param string $foreignPivotKey - * @param string $relatedPivotKey - * @param string $parentKey - * @param string $relatedKey - * @param bool $inverse + * @param string $related + * @param string $name + * @param string $table + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey + * @param string $relatedKey + * @param bool $inverse * @return \Hyperf\Database\Model\Relations\MorphToMany */ public function morphToMany( @@ -373,7 +374,7 @@ trait HasRelationships // instances, as well as the relationship instances we need for these. $instance = $this->newRelatedInstance($related); - $foreignPivotKey = $foreignPivotKey ?: $name.'_id'; + $foreignPivotKey = $foreignPivotKey ?: $name . '_id'; $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey(); @@ -385,7 +386,7 @@ trait HasRelationships $lastWord = array_pop($words); - $table = implode('', $words).Str::plural($lastWord); + $table = implode('', $words) . Str::plural($lastWord); } return $this->newMorphToMany( @@ -405,13 +406,13 @@ trait HasRelationships /** * Define a polymorphic, inverse many-to-many relationship. * - * @param string $related - * @param string $name - * @param string $table - * @param string $foreignPivotKey - * @param string $relatedPivotKey - * @param string $parentKey - * @param string $relatedKey + * @param string $related + * @param string $name + * @param string $table + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey + * @param string $relatedKey * @return \Hyperf\Database\Model\Relations\MorphToMany */ public function morphedByMany( @@ -428,7 +429,7 @@ trait HasRelationships // For the inverse of the polymorphic many-to-many relations, we will change // the way we determine the foreign and other keys, as it is the opposite // of the morph-to-many method since we're figuring out these inverses. - $relatedPivotKey = $relatedPivotKey ?: $name.'_id'; + $relatedPivotKey = $relatedPivotKey ?: $name . '_id'; return $this->morphToMany( $related, @@ -445,8 +446,8 @@ trait HasRelationships /** * Get the joining table name for a many-to-many relation. * - * @param string $related - * @param \Hyperf\Database\Model\Model|null $instance + * @param string $related + * @param \Hyperf\Database\Model\Model|null $instance * @return string */ public function joiningTable($related, $instance = null) @@ -481,7 +482,7 @@ trait HasRelationships /** * Determine if the model touches a given relation. * - * @param string $relation + * @param string $relation * @return bool */ public function touches($relation) @@ -491,8 +492,6 @@ trait HasRelationships /** * Touch the owning relations of the model. - * - * @return void */ public function touchOwners() { @@ -540,8 +539,7 @@ trait HasRelationships /** * Get a specified relationship. * - * @param string $relation - * @return mixed + * @param string $relation */ public function getRelation($relation) { @@ -551,7 +549,7 @@ trait HasRelationships /** * Determine if the given relation is loaded. * - * @param string $key + * @param string $key * @return bool */ public function relationLoaded($key) @@ -562,8 +560,7 @@ trait HasRelationships /** * Set the given relationship on the model. * - * @param string $relation - * @param mixed $value + * @param string $relation * @return $this */ public function setRelation($relation, $value) @@ -576,7 +573,7 @@ trait HasRelationships /** * Unset a loaded relationship. * - * @param string $relation + * @param string $relation * @return $this */ public function unsetRelation($relation) @@ -589,7 +586,6 @@ trait HasRelationships /** * Set the entire relations array on the model. * - * @param array $relations * @return $this */ public function setRelations(array $relations) @@ -612,7 +608,6 @@ trait HasRelationships /** * Set the relationships that are touched on save. * - * @param array $touches * @return $this */ public function setTouchedRelations(array $touches) @@ -625,10 +620,8 @@ trait HasRelationships /** * Instantiate a new HasOne relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $foreignKey - * @param string $localKey + * @param string $foreignKey + * @param string $localKey * @return \Hyperf\Database\Model\Relations\HasOne */ protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey) @@ -639,13 +632,10 @@ trait HasRelationships /** * Instantiate a new HasOneThrough relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $farParent - * @param \Hyperf\Database\Model\Model $throughParent - * @param string $firstKey - * @param string $secondKey - * @param string $localKey - * @param string $secondLocalKey + * @param string $firstKey + * @param string $secondKey + * @param string $localKey + * @param string $secondLocalKey * @return \Hyperf\Database\Model\Relations\HasOneThrough */ protected function newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey) @@ -656,11 +646,9 @@ trait HasRelationships /** * Instantiate a new MorphOne relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $type - * @param string $id - * @param string $localKey + * @param string $type + * @param string $id + * @param string $localKey * @return \Hyperf\Database\Model\Relations\MorphOne */ protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey) @@ -671,11 +659,9 @@ trait HasRelationships /** * Instantiate a new BelongsTo relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $child - * @param string $foreignKey - * @param string $ownerKey - * @param string $relation + * @param string $foreignKey + * @param string $ownerKey + * @param string $relation * @return \Hyperf\Database\Model\Relations\BelongsTo */ protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $ownerKey, $relation) @@ -686,10 +672,10 @@ trait HasRelationships /** * Define a polymorphic, inverse one-to-one or many relationship. * - * @param string $name - * @param string $type - * @param string $id - * @param string $ownerKey + * @param string $name + * @param string $type + * @param string $id + * @param string $ownerKey * @return \Hyperf\Database\Model\Relations\MorphTo */ protected function morphEagerTo($name, $type, $id, $ownerKey) @@ -707,11 +693,11 @@ trait HasRelationships /** * Define a polymorphic, inverse one-to-one or many relationship. * - * @param string $target - * @param string $name - * @param string $type - * @param string $id - * @param string $ownerKey + * @param string $target + * @param string $name + * @param string $type + * @param string $id + * @param string $ownerKey * @return \Hyperf\Database\Model\Relations\MorphTo */ protected function morphInstanceTo($target, $name, $type, $id, $ownerKey) @@ -733,12 +719,10 @@ trait HasRelationships /** * Instantiate a new MorphTo relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $foreignKey - * @param string $ownerKey - * @param string $type - * @param string $relation + * @param string $foreignKey + * @param string $ownerKey + * @param string $type + * @param string $relation * @return \Hyperf\Database\Model\Relations\MorphTo */ protected function newMorphTo(Builder $query, Model $parent, $foreignKey, $ownerKey, $type, $relation) @@ -761,10 +745,8 @@ trait HasRelationships /** * Instantiate a new HasMany relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $foreignKey - * @param string $localKey + * @param string $foreignKey + * @param string $localKey * @return \Hyperf\Database\Model\Relations\HasMany */ protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey) @@ -775,13 +757,10 @@ trait HasRelationships /** * Instantiate a new HasManyThrough relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $farParent - * @param \Hyperf\Database\Model\Model $throughParent - * @param string $firstKey - * @param string $secondKey - * @param string $localKey - * @param string $secondLocalKey + * @param string $firstKey + * @param string $secondKey + * @param string $localKey + * @param string $secondLocalKey * @return \Hyperf\Database\Model\Relations\HasManyThrough */ protected function newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey) @@ -792,11 +771,9 @@ trait HasRelationships /** * Instantiate a new MorphMany relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $type - * @param string $id - * @param string $localKey + * @param string $type + * @param string $id + * @param string $localKey * @return \Hyperf\Database\Model\Relations\MorphMany */ protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey) @@ -807,14 +784,12 @@ trait HasRelationships /** * Instantiate a new BelongsToMany relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $table - * @param string $foreignPivotKey - * @param string $relatedPivotKey - * @param string $parentKey - * @param string $relatedKey - * @param string $relationName + * @param string $table + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey + * @param string $relatedKey + * @param string $relationName * @return \Hyperf\Database\Model\Relations\BelongsToMany */ protected function newBelongsToMany( @@ -833,16 +808,14 @@ trait HasRelationships /** * Instantiate a new MorphToMany relationship. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Model $parent - * @param string $name - * @param string $table - * @param string $foreignPivotKey - * @param string $relatedPivotKey - * @param string $parentKey - * @param string $relatedKey - * @param string $relationName - * @param bool $inverse + * @param string $name + * @param string $table + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey + * @param string $relatedKey + * @param string $relationName + * @param bool $inverse * @return \Hyperf\Database\Model\Relations\MorphToMany */ protected function newMorphToMany( @@ -891,25 +864,24 @@ trait HasRelationships /** * Get the polymorphic relationship columns. * - * @param string $name - * @param string $type - * @param string $id + * @param string $name + * @param string $type + * @param string $id * @return array */ protected function getMorphs($name, $type, $id) { - return [$type ?: $name.'_type', $id ?: $name.'_id']; + return [$type ?: $name . '_type', $id ?: $name . '_id']; } /** * Create a new model instance for a related model. * - * @param string $class - * @return mixed + * @param string $class */ protected function newRelatedInstance($class) { - return tap(new $class, function ($instance) { + return tap(new $class(), function ($instance) { if (! $instance->getConnectionName()) { $instance->setConnection($this->connection); } diff --git a/src/database/src/Model/Concerns/HasTimestamps.php b/src/database/src/Model/Concerns/HasTimestamps.php index 17d2a2d36..14ac35c78 100644 --- a/src/database/src/Model/Concerns/HasTimestamps.php +++ b/src/database/src/Model/Concerns/HasTimestamps.php @@ -1,4 +1,5 @@ =', $count = 1, $boolean = 'and', Closure $callback = null) { - if (strpos($relation, '.') !== false) { + if (false !== strpos($relation, '.')) { return $this->hasNested($relation, $operator, $count, $boolean, $callback); } @@ -75,9 +75,9 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with an "or". * - * @param string $relation - * @param string $operator - * @param int $count + * @param string $relation + * @param string $operator + * @param int $count * @return \Hyperf\Database\Model\Builder|static */ public function orHas($relation, $operator = '>=', $count = 1) @@ -88,9 +88,8 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query. * - * @param string $relation - * @param string $boolean - * @param \Closure|null $callback + * @param string $relation + * @param string $boolean * @return \Hyperf\Database\Model\Builder|static */ public function doesntHave($relation, $boolean = 'and', Closure $callback = null) @@ -101,7 +100,7 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with an "or". * - * @param string $relation + * @param string $relation * @return \Hyperf\Database\Model\Builder|static */ public function orDoesntHave($relation) @@ -112,10 +111,9 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with where clauses. * - * @param string $relation - * @param \Closure|null $callback - * @param string $operator - * @param int $count + * @param string $relation + * @param string $operator + * @param int $count * @return \Hyperf\Database\Model\Builder|static */ public function whereHas($relation, Closure $callback = null, $operator = '>=', $count = 1) @@ -126,10 +124,10 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with where clauses and an "or". * - * @param string $relation - * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $relation + * @param \Closure $callback + * @param string $operator + * @param int $count * @return \Hyperf\Database\Model\Builder|static */ public function orWhereHas($relation, Closure $callback = null, $operator = '>=', $count = 1) @@ -140,8 +138,7 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with where clauses. * - * @param string $relation - * @param \Closure|null $callback + * @param string $relation * @return \Hyperf\Database\Model\Builder|static */ public function whereDoesntHave($relation, Closure $callback = null) @@ -152,8 +149,8 @@ trait QueriesRelationships /** * Add a relationship count / exists condition to the query with where clauses and an "or". * - * @param string $relation - * @param \Closure $callback + * @param string $relation + * @param \Closure $callback * @return \Hyperf\Database\Model\Builder|static */ public function orWhereDoesntHave($relation, Closure $callback = null) @@ -164,7 +161,6 @@ trait QueriesRelationships /** * Add subselect queries to count the relations. * - * @param mixed $relations * @return $this */ public function withCount($relations) @@ -174,7 +170,7 @@ trait QueriesRelationships } if (is_null($this->query->columns)) { - $this->query->select([$this->query->from.'.*']); + $this->query->select([$this->query->from . '.*']); } $relations = is_array($relations) ? $relations : func_get_args(); @@ -187,7 +183,7 @@ trait QueriesRelationships unset($alias); - if (count($segments) === 3 && Str::lower($segments[1]) === 'as') { + if (3 === count($segments) && 'as' === Str::lower($segments[1])) { [$name, $alias] = [$segments[0], $segments[2]]; } @@ -212,7 +208,7 @@ trait QueriesRelationships // Finally we will add the proper result column alias to the query and run the subselect // statement against the query builder. Then we will return the builder instance back // to the developer for further constraint chaining that needs to take place on it. - $column = $alias ?? Str::snake($name.'_count'); + $column = $alias ?? Str::snake($name . '_count'); $this->selectSub($query, $column); } @@ -223,7 +219,6 @@ trait QueriesRelationships /** * Merge the where constraints from another query to the current query. * - * @param \Hyperf\Database\Model\Builder $from * @return \Hyperf\Database\Model\Builder|static */ public function mergeConstraintsFrom(Builder $from) @@ -246,18 +241,18 @@ trait QueriesRelationships * * Sets up recursive call to whereHas until we finish the nested relation. * - * @param string $relations - * @param string $operator - * @param int $count - * @param string $boolean - * @param \Closure|null $callback + * @param string $relations + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure|null $callback * @return \Hyperf\Database\Model\Builder|static */ protected function hasNested($relations, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) { $relations = explode('.', $relations); - $doesntHave = $operator === '<' && $count === 1; + $doesntHave = '<' === $operator && 1 === $count; if ($doesntHave) { $operator = '>='; @@ -279,11 +274,9 @@ trait QueriesRelationships /** * Add the "has" condition where clause to the query. * - * @param \Hyperf\Database\Model\Builder $hasQuery - * @param \Hyperf\Database\Model\Relations\Relation $relation - * @param string $operator - * @param int $count - * @param string $boolean + * @param string $operator + * @param int $count + * @param string $boolean * @return \Hyperf\Database\Model\Builder|static */ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean) @@ -291,17 +284,16 @@ trait QueriesRelationships $hasQuery->mergeConstraintsFrom($relation->getQuery()); return $this->canUseExistsForExistenceCheck($operator, $count) - ? $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, $operator === '<' && $count === 1) + ? $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, '<' === $operator && 1 === $count) : $this->addWhereCountQuery($hasQuery->toBase(), $operator, $count, $boolean); } /** * Add a sub-query count clause to this query. * - * @param \Hyperf\Database\Query\Builder $query - * @param string $operator - * @param int $count - * @param string $boolean + * @param string $operator + * @param int $count + * @param string $boolean * @return $this */ protected function addWhereCountQuery(QueryBuilder $query, $operator = '>=', $count = 1, $boolean = 'and') @@ -309,7 +301,7 @@ trait QueriesRelationships $this->query->addBinding($query->getBindings(), 'where'); return $this->where( - new Expression('('.$query->toSql().')'), + new Expression('(' . $query->toSql() . ')'), $operator, is_numeric($count) ? new Expression($count) : $count, $boolean @@ -319,7 +311,7 @@ trait QueriesRelationships /** * Get the "has relation" base query instance. * - * @param string $relation + * @param string $relation * @return \Hyperf\Database\Model\Relations\Relation */ protected function getRelationWithoutConstraints($relation) @@ -332,12 +324,12 @@ trait QueriesRelationships /** * Check if we can run an "exists" query to optimize performance. * - * @param string $operator - * @param int $count + * @param string $operator + * @param int $count * @return bool */ protected function canUseExistsForExistenceCheck($operator, $count) { - return ($operator === '>=' || $operator === '<') && $count === 1; + return ('>=' === $operator || '<' === $operator) && 1 === $count; } } diff --git a/src/database/src/Model/Events/Booted.php b/src/database/src/Model/Events/Booted.php index fd24d3695..2cdabcb6a 100644 --- a/src/database/src/Model/Events/Booted.php +++ b/src/database/src/Model/Events/Booted.php @@ -1,4 +1,5 @@ model; } - /** - * @return string - */ public function getMethod(): string { return $this->method; diff --git a/src/database/src/Model/Events/ForceDeleted.php b/src/database/src/Model/Events/ForceDeleted.php index fa71137f7..e156e236f 100644 --- a/src/database/src/Model/Events/ForceDeleted.php +++ b/src/database/src/Model/Events/ForceDeleted.php @@ -1,4 +1,5 @@ amount === null) { + if (null === $this->amount) { return tap($this->makeInstance($attributes), function ($instance) { $this->callAfterMaking(collect([$instance])); }); } if ($this->amount < 1) { - return (new $this->class)->newCollection(); + return (new $this->class())->newCollection(); } - $instances = (new $this->class)->newCollection(array_map(function () use ($attributes) { + $instances = (new $this->class())->newCollection(array_map(function () use ($attributes) { return $this->makeInstance($attributes); }, range(1, $this->amount))); @@ -234,13 +222,10 @@ class FactoryBuilder /** * Create an array of raw attribute arrays. - * - * @param array $attributes - * @return mixed */ public function raw(array $attributes = []) { - if ($this->amount === null) { + if (null === $this->amount) { return $this->getRawAttributes($attributes); } @@ -256,8 +241,7 @@ class FactoryBuilder /** * Run after making callbacks on a collection of models. * - * @param \Hyperf\Utils\Collection $models - * @return void + * @param \Hyperf\Utils\Collection $models */ public function callAfterMaking($models) { @@ -267,8 +251,7 @@ class FactoryBuilder /** * Run after creating callbacks on a collection of models. * - * @param \Hyperf\Utils\Collection $models - * @return void + * @param \Hyperf\Utils\Collection $models */ public function callAfterCreating($models) { @@ -278,8 +261,7 @@ class FactoryBuilder /** * Set the connection name on the results and store them. * - * @param \Hyperf\Utils\Collection $results - * @return void + * @param \Hyperf\Utils\Collection $results */ protected function store($results) { @@ -295,8 +277,6 @@ class FactoryBuilder /** * Get a raw attributes array for the model. * - * @param array $attributes - * @return mixed * * @throws \InvalidArgumentException */ @@ -320,7 +300,6 @@ class FactoryBuilder /** * Make an instance of the model with the given attributes. * - * @param array $attributes * @return \Hyperf\Database\Model\Model */ protected function makeInstance(array $attributes = []) @@ -341,8 +320,6 @@ class FactoryBuilder /** * Apply the active states to the model definition array. * - * @param array $definition - * @param array $attributes * @return array * * @throws \InvalidArgumentException @@ -370,8 +347,7 @@ class FactoryBuilder /** * Get the state attributes. * - * @param string $state - * @param array $attributes + * @param string $state * @return array */ protected function stateAttributes($state, array $attributes) @@ -392,7 +368,6 @@ class FactoryBuilder /** * Expand all attributes to their underlying values. * - * @param array $attributes * @return array */ protected function expandAttributes(array $attributes) @@ -417,9 +392,7 @@ class FactoryBuilder /** * Call after callbacks for each model and state. * - * @param array $afterCallbacks - * @param \Hyperf\Utils\Collection $models - * @return void + * @param \Hyperf\Utils\Collection $models */ protected function callAfter(array $afterCallbacks, $models) { @@ -435,10 +408,8 @@ class FactoryBuilder /** * Call after callbacks for each model and state. * - * @param array $afterCallbacks - * @param \Hyperf\Database\Model\Model $model - * @param string $state - * @return void + * @param \Hyperf\Database\Model\Model $model + * @param string $state */ protected function callAfterCallbacks(array $afterCallbacks, $model, $state) { @@ -454,7 +425,7 @@ class FactoryBuilder /** * Determine if the given state has an "after" callback. * - * @param string $state + * @param string $state * @return bool */ protected function stateHasAfterCallback($state) diff --git a/src/database/src/Model/GlobalScope.php b/src/database/src/Model/GlobalScope.php index 6a0de2710..5e3cedd4b 100644 --- a/src/database/src/Model/GlobalScope.php +++ b/src/database/src/Model/GlobalScope.php @@ -1,4 +1,5 @@ getKey().'] to JSON: '.$message); + return new static('Error encoding model [' . get_class($model) . '] with ID [' . $model->getKey() . '] to JSON: ' . $message); } /** * Create a new JSON encoding exception for an attribute. * - * @param mixed $model - * @param mixed $key * @param string $message * @return static */ diff --git a/src/database/src/Model/MassAssignmentException.php b/src/database/src/Model/MassAssignmentException.php index fce30c455..5c6e07e38 100755 --- a/src/database/src/Model/MassAssignmentException.php +++ b/src/database/src/Model/MassAssignmentException.php @@ -1,4 +1,5 @@ $method(...$parameters); + return (new static())->$method(...$parameters); } /** * Convert the model to its string representation. - * - * @return string */ public function __toString(): string { @@ -215,8 +205,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * When a model is being unserialized, check if it needs to be booted. - * - * @return void */ public function __wakeup() { @@ -225,9 +213,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Disables relationship model touching for the current class during given callback scope. - * - * @param callable $callback - * @return void */ public static function withoutTouching(callable $callback) { @@ -236,10 +221,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Disables relationship model touching for the given model classes during given callback scope. - * - * @param array $models - * @param callable $callback - * @return void */ public static function withoutTouchingOn(array $models, callable $callback) { @@ -274,7 +255,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Fill the model with an array of attributes. * - * @param array $attributes * @return $this * @throws \Hyperf\Database\Model\MassAssignmentException */ @@ -301,7 +281,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Fill the model with an array of attributes. Force mass assignment. * - * @param array $attributes * @return $this */ public function forceFill(array $attributes) @@ -329,8 +308,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Create a new instance of the given model. * - * @param array $attributes - * @param bool $exists + * @param array $attributes + * @param bool $exists * @return static */ public function newInstance($attributes = [], $exists = false) @@ -338,7 +317,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab // This method just provides a convenient way for us to generate fresh model // instances of this current model. It is particularly useful during the // hydration of new objects via the Model query builder instances. - $model = new static((array)$attributes); + $model = new static((array) $attributes); $model->exists = $exists; @@ -352,7 +331,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Create a new model instance that is existing. * - * @param array $attributes + * @param array $attributes * @param string|null $connection * @return static */ @@ -360,7 +339,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab { $model = $this->newInstance([], true); - $model->setRawAttributes((array)$attributes, true); + $model->setRawAttributes((array) $attributes, true); $model->setConnection($connection ? : $this->getConnectionName()); @@ -372,7 +351,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Begin querying the model on a given connection. * - * @param string|null $connection + * @param string|null $connection * @return \Hyperf\Database\Model\Builder */ public static function on($connection = null) @@ -380,7 +359,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab // First we will just create a fresh instance of this model, and then we can set the // connection on the model so that it is used for the queries we execute, as well // as being set on every relation we retrieve without a custom connection name. - $instance = new static; + $instance = new static(); $instance->setConnection($connection); @@ -400,7 +379,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get all of the models from the database. * - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Collection|static[] */ public static function all($columns = ['*']) @@ -411,7 +390,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Begin querying a model with eager loading. * - * @param array|string $relations + * @param array|string $relations * @return \Hyperf\Database\Model\Builder|static */ public static function with($relations) @@ -467,8 +446,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Update the model in the database. * - * @param array $attributes - * @param array $options * @return bool */ public function update(array $attributes = [], array $options = []) @@ -510,7 +487,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Save the model to the database. * - * @param array $options * @return bool */ public function save(array $options = []) @@ -520,7 +496,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This provides a chance for any // listeners to cancel save operations if validations fail or whatever. - if ($this->fireModelEvent('saving') === false) { + if (false === $this->fireModelEvent('saving')) { return false; } @@ -555,7 +531,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Save the model to the database using transaction. * - * @param array $options * @return bool * @throws \Throwable */ @@ -588,11 +563,11 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab // We will actually pull the models from the database table and call delete on // each of them individually so that their events get fired properly with a // correct set of attributes in case the developers wants to check these. - $key = ($instance = new static)->getKeyName(); + $key = ($instance = new static())->getKeyName(); foreach ($instance->whereIn($key, $ids)->get() as $model) { if ($model->delete()) { - $count++; + ++$count; } } @@ -618,7 +593,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab return; } - if ($this->fireModelEvent('deleting') === false) { + if (false === $this->fireModelEvent('deleting')) { return false; } @@ -655,7 +630,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ public static function query() { - return (new static)->newQuery(); + return (new static())->newQuery(); } /** @@ -727,7 +702,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get a new query to restore one or more models by their queueable IDs. * - * @param array|int $ids + * @param array|int $ids * @return \Hyperf\Database\Model\Builder */ public function newQueryForRestoration($ids) @@ -739,7 +714,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Create a new Model query builder for the model. * - * @param \Hyperf\Database\Query\Builder $query + * @param \Hyperf\Database\Query\Builder $query * @return \Hyperf\Database\Model\Builder|static */ public function newModelBuilder($query) @@ -750,7 +725,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Create a new Model Collection instance. * - * @param array $models * @return \Hyperf\Database\Model\Collection */ public function newCollection(array $models = []) @@ -761,11 +735,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Create a new pivot model instance. * - * @param \Hyperf\Database\Model\Model $parent - * @param array $attributes - * @param string $table - * @param bool $exists - * @param string|null $using + * @param \Hyperf\Database\Model\Model $parent + * @param string $table + * @param bool $exists + * @param string|null $using * @return \Hyperf\Database\Model\Relations\Pivot */ public function newPivot(self $parent, array $attributes, $table, $exists, $using = null) @@ -775,8 +748,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Convert the model instance to an array. - * - * @return array */ public function toArray(): array { @@ -786,7 +757,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Convert the model instance to JSON. * - * @param int $options + * @param int $options * @return string * @throws \Hyperf\Database\Model\JsonEncodingException */ @@ -852,7 +823,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Clone the model into a new, non-existing instance. * - * @param array|null $except * @return static */ public function replicate(array $except = null) @@ -865,7 +835,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab $attributes = Arr::except($this->attributes, $except ? array_unique(array_merge($except, $defaults)) : $defaults); - return tap(new static, function ($instance) use ($attributes) { + return tap(new static(), function ($instance) use ($attributes) { $instance->setRawAttributes($attributes); $instance->setRelations($this->relations); @@ -880,7 +850,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ public function is($model) { - return ! is_null($model) && $this->getKey() === $model->getKey() && $this->getTable() === $model->getTable() && $this->getConnectionName() === $model->getConnectionName(); + return ! is_null($model) && + $this->getKey() === $model->getKey() && + $this->getTable() === $model->getTable() && + $this->getConnectionName() === $model->getConnectionName(); } /** @@ -897,8 +870,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the database connection for the model. * You can write it by yourself. - * - * @return ConnectionInterface */ public function getConnection(): ConnectionInterface { @@ -1031,7 +1002,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Set whether IDs are incrementing. * - * @param bool $value + * @param bool $value * @return $this */ public function setIncrementing($value) @@ -1043,8 +1014,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the value of the model's primary key. - * - * @return mixed */ public function getKey() { @@ -1053,8 +1022,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the queueable identity for the entity. - * - * @return mixed */ public function getQueueableId() { @@ -1093,8 +1060,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the queueable connection for the entity. - * - * @return mixed */ public function getQueueableConnection() { @@ -1103,8 +1068,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the value of the model's route key. - * - * @return mixed */ public function getRouteKey() { @@ -1124,7 +1087,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Retrieve the model for a bound value. * - * @param mixed $value * @return \Hyperf\Database\Model\Model|null */ public function resolveRouteBinding($value) @@ -1155,7 +1117,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Set the number of models to return per page. * - * @param int $perPage + * @param int $perPage * @return $this */ public function setPerPage($perPage) @@ -1168,7 +1130,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Determine if the given attribute exists. * - * @param mixed $offset * @return bool */ public function offsetExists($offset) @@ -1178,9 +1139,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the value for a given offset. - * - * @param mixed $offset - * @return mixed */ public function offsetGet($offset) { @@ -1189,10 +1147,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Set the value for a given offset. - * - * @param mixed $offset - * @param mixed $value - * @return void */ public function offsetSet($offset, $value) { @@ -1201,9 +1155,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Unset the value for a given offset. - * - * @param mixed $offset - * @return void */ public function offsetUnset($offset) { @@ -1269,9 +1220,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Increment a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ protected function increment($column, $amount = 1, array $extra = []) @@ -1282,9 +1232,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Decrement a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ protected function decrement($column, $amount = 1, array $extra = []) @@ -1295,10 +1244,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Run the increment or decrement method on the model. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra - * @param string $method + * @param array $extra + * @param string $method * @return int */ protected function incrementOrDecrement($column, $amount, $extra, $method) @@ -1317,15 +1266,14 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Increment the underlying attribute value and sync with original. * - * @param string $column - * @param float|int $amount - * @param array $extra - * @param string $method - * @return void + * @param string $column + * @param float|int $amount + * @param array $extra + * @param string $method */ protected function incrementOrDecrementAttributeValue($column, $amount, $extra, $method) { - $this->{$column} = $this->{$column} + ($method === 'increment' ? $amount : $amount * -1); + $this->{$column} = $this->{$column} + ('increment' === $method ? $amount : $amount * -1); $this->forceFill($extra); @@ -1334,9 +1282,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Perform any actions that are necessary after the model is saved. - * - * @param array $options - * @return void */ protected function finishSave(array $options) { @@ -1360,7 +1305,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab // If the updating event returns false, we will cancel the update operation so // developers can hook Validation systems into their models and cancel this // operation if the model does not pass validation. Otherwise, we update. - if ($this->fireModelEvent('updating') === false) { + if (false === $this->fireModelEvent('updating')) { return false; } @@ -1402,8 +1347,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Get the primary key value for a save query. - * - * @return mixed */ protected function getKeyForSaveQuery() { @@ -1418,7 +1361,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ protected function performInsert(Builder $query) { - if ($this->fireModelEvent('creating') === false) { + if (false === $this->fireModelEvent('creating')) { return false; } @@ -1464,9 +1407,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Insert the given attributes and set the ID on the model. * - * @param \Hyperf\Database\Model\Builder $query - * @param array $attributes - * @return void + * @param \Hyperf\Database\Model\Builder $query + * @param array $attributes */ protected function insertAndSetId(Builder $query, $attributes) { @@ -1477,8 +1419,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab /** * Perform the actual delete query on this model instance. - * - * @return void */ protected function performDeleteOnModel() { diff --git a/src/database/src/Model/ModelNotFoundException.php b/src/database/src/Model/ModelNotFoundException.php index f56f2c2ea..494e5b830 100755 --- a/src/database/src/Model/ModelNotFoundException.php +++ b/src/database/src/Model/ModelNotFoundException.php @@ -1,4 +1,5 @@ message = "No query results for model [{$model}]"; if (count($this->ids) > 0) { - $this->message .= ' '.implode(', ', $this->ids); + $this->message .= ' ' . implode(', ', $this->ids); } else { $this->message .= '.'; } diff --git a/src/database/src/Model/Register.php b/src/database/src/Model/Register.php index 8cc34cecc..07188e3e4 100644 --- a/src/database/src/Model/Register.php +++ b/src/database/src/Model/Register.php @@ -1,4 +1,5 @@ related->getTable(); - $this->query->where($table.'.'.$this->ownerKey, '=', $this->child->{$this->foreignKey}); + $this->query->where($table . '.' . $this->ownerKey, '=', $this->child->{$this->foreignKey}); } } /** * Set the constraints for an eager load of the relation. - * - * @param array $models - * @return void */ public function addEagerConstraints(array $models) { // We'll grab the primary key name of the related models since it could be set to // a non-standard name and not "id". We will then construct the constraint for // our eagerly loading query so it returns the proper models from execution. - $key = $this->related->getTable().'.'.$this->ownerKey; + $key = $this->related->getTable() . '.' . $this->ownerKey; $whereIn = $this->whereInMethod($this->related, $this->ownerKey); @@ -126,8 +116,7 @@ class BelongsTo extends Relation /** * Initialize the relation on a set of models. * - * @param array $models - * @param string $relation + * @param string $relation * @return array */ public function initRelation(array $models, $relation) @@ -142,9 +131,7 @@ class BelongsTo extends Relation /** * Match the eagerly loaded results to their parents. * - * @param array $models - * @param \Hyperf\Database\Model\Collection $results - * @param string $relation + * @param string $relation * @return array */ public function match(array $models, Collection $results, $relation) @@ -176,9 +163,6 @@ class BelongsTo extends Relation /** * Update the parent model on the relationship. - * - * @param array $attributes - * @return mixed */ public function update(array $attributes) { @@ -188,7 +172,7 @@ class BelongsTo extends Relation /** * Associate the model instance to the given parent. * - * @param \Hyperf\Database\Model\Model|int|string $model + * @param \Hyperf\Database\Model\Model|int|string $model * @return \Hyperf\Database\Model\Model */ public function associate($model) @@ -221,9 +205,7 @@ class BelongsTo extends Relation /** * Add the constraints for a relationship query. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) @@ -242,21 +224,19 @@ class BelongsTo extends Relation /** * Add the constraints for a relationship query on the same table. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) { $query->select($columns)->from( - $query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash() + $query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash() ); $query->getModel()->setTable($hash); return $query->whereColumn( - $hash.'.'.$this->ownerKey, + $hash . '.' . $this->ownerKey, '=', $this->getQualifiedForeignKeyName() ); @@ -269,7 +249,7 @@ class BelongsTo extends Relation */ public function getRelationCountHash() { - return 'laravel_reserved_'.static::$selfJoinCount++; + return 'laravel_reserved_' . static::$selfJoinCount++; } /** @@ -346,7 +326,6 @@ class BelongsTo extends Relation /** * Gather the keys from an array of related models. * - * @param array $models * @return array */ protected function getEagerModelKeys(array $models) @@ -365,7 +344,7 @@ class BelongsTo extends Relation // If there are no keys that were not null we will just return an array with null // so this query wont fail plus returns zero results, which should be what the // developer expects to happen in this situation. Otherwise we'll sort them. - if (count($keys) === 0) { + if (0 === count($keys)) { return [null]; } @@ -382,13 +361,12 @@ class BelongsTo extends Relation protected function relationHasIncrementingId() { return $this->related->getIncrementing() && - $this->related->getKeyType() === 'int'; + 'int' === $this->related->getKeyType(); } /** * Make a new related instance for the given model. * - * @param \Hyperf\Database\Model\Model $parent * @return \Hyperf\Database\Model\Model */ protected function newRelatedInstanceFor(Model $parent) diff --git a/src/database/src/Model/Relations/BelongsToMany.php b/src/database/src/Model/Relations/BelongsToMany.php index 83e8fd11f..a3fc5d47a 100755 --- a/src/database/src/Model/Relations/BelongsToMany.php +++ b/src/database/src/Model/Relations/BelongsToMany.php @@ -1,4 +1,5 @@ pivotWheres[] = func_get_args(); - return $this->where($this->table.'.'.$column, $operator, $value, $boolean); + return $this->where($this->table . '.' . $column, $operator, $value, $boolean); } /** * Set a "where in" clause for a pivot table column. * - * @param string $column - * @param mixed $values - * @param string $boolean - * @param bool $not + * @param string $column + * @param string $boolean + * @param bool $not * @return $this */ public function wherePivotIn($column, $values, $boolean = 'and', $not = false) { $this->pivotWhereIns[] = func_get_args(); - return $this->whereIn($this->table.'.'.$column, $values, $boolean, $not); + return $this->whereIn($this->table . '.' . $column, $values, $boolean, $not); } /** * Set an "or where" clause for a pivot table column. * - * @param string $column - * @param string $operator - * @param mixed $value + * @param string $column + * @param string $operator * @return $this */ public function orWherePivot($column, $operator = null, $value = null) @@ -326,8 +313,7 @@ class BelongsToMany extends Relation * * In addition, new pivot records will receive this value. * - * @param string|array $column - * @param mixed $value + * @param string|array $column * @return $this */ public function withPivotValue($column, $value = null) @@ -352,8 +338,7 @@ class BelongsToMany extends Relation /** * Set an "or where in" clause for a pivot table column. * - * @param string $column - * @param mixed $values + * @param string $column * @return $this */ public function orWherePivotIn($column, $values) @@ -364,8 +349,7 @@ class BelongsToMany extends Relation /** * Find a related model by its primary key or return new instance of the related model. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model */ public function findOrNew($id, $columns = ['*']) @@ -380,7 +364,6 @@ class BelongsToMany extends Relation /** * Get the first related model record matching the attributes or instantiate it. * - * @param array $attributes * @return \Hyperf\Database\Model\Model */ public function firstOrNew(array $attributes) @@ -395,9 +378,7 @@ class BelongsToMany extends Relation /** * Get the first related record matching the attributes or create it. * - * @param array $attributes - * @param array $joining - * @param bool $touch + * @param bool $touch * @return \Hyperf\Database\Model\Model */ public function firstOrCreate(array $attributes, array $joining = [], $touch = true) @@ -412,10 +393,7 @@ class BelongsToMany extends Relation /** * Create or update a related record matching the attributes, and fill it with values. * - * @param array $attributes - * @param array $values - * @param array $joining - * @param bool $touch + * @param bool $touch * @return \Hyperf\Database\Model\Model */ public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true) @@ -434,8 +412,7 @@ class BelongsToMany extends Relation /** * Find a related model by its primary key. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|null */ public function find($id, $columns = ['*']) @@ -450,8 +427,7 @@ class BelongsToMany extends Relation /** * Find multiple related models by their primary keys. * - * @param mixed $ids - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection */ public function findMany($ids, $columns = ['*']) @@ -465,8 +441,7 @@ class BelongsToMany extends Relation /** * Find a related model by its primary key or throw an exception. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection * * @throws \Hyperf\Database\Model\ModelNotFoundException @@ -483,14 +458,13 @@ class BelongsToMany extends Relation return $result; } - throw (new ModelNotFoundException)->setModel(get_class($this->related), $id); + throw (new ModelNotFoundException())->setModel(get_class($this->related), $id); } /** * Execute the query and get the first result. * - * @param array $columns - * @return mixed + * @param array $columns */ public function first($columns = ['*']) { @@ -502,7 +476,7 @@ class BelongsToMany extends Relation /** * Execute the query and get the first result or throw an exception. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|static * * @throws \Hyperf\Database\Model\ModelNotFoundException @@ -513,13 +487,11 @@ class BelongsToMany extends Relation return $model; } - throw (new ModelNotFoundException)->setModel(get_class($this->related)); + throw (new ModelNotFoundException())->setModel(get_class($this->related)); } /** * Get the results of the relationship. - * - * @return mixed */ public function getResults() { @@ -529,7 +501,7 @@ class BelongsToMany extends Relation /** * Execute the query as a "select" statement. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection */ public function get($columns = ['*']) @@ -560,10 +532,10 @@ class BelongsToMany extends Relation /** * Get a paginator for the "select" statement. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page * @return \Hyperf\Contracts\Pagination\LengthAwarePaginator */ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) @@ -578,10 +550,10 @@ class BelongsToMany extends Relation /** * Paginate the given query into a simple paginator. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page * @return \Hyperf\Contracts\Pagination\Paginator */ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) @@ -597,7 +569,6 @@ class BelongsToMany extends Relation * Chunk the results of the query. * * @param int $count - * @param callable $callback * @return bool */ public function chunk($count, callable $callback) @@ -614,7 +585,6 @@ class BelongsToMany extends Relation /** * Execute a callback over each item while chunking. * - * @param callable $callback * @param int $count * @return bool */ @@ -622,7 +592,7 @@ class BelongsToMany extends Relation { return $this->chunk($count, function ($results) use ($callback) { foreach ($results as $key => $value) { - if ($callback($value, $key) === false) { + if (false === $callback($value, $key)) { return false; } } @@ -631,8 +601,6 @@ class BelongsToMany extends Relation /** * If we're touching the parent model, touch. - * - * @return void */ public function touchIfTouching() { @@ -649,8 +617,6 @@ class BelongsToMany extends Relation * Touch all of the related models for the relationship. * * E.g.: Touch all roles associated with this user. - * - * @return void */ public function touch() { @@ -681,9 +647,7 @@ class BelongsToMany extends Relation /** * Save a new model and attach it to the parent model. * - * @param \Hyperf\Database\Model\Model $model - * @param array $pivotAttributes - * @param bool $touch + * @param bool $touch * @return \Hyperf\Database\Model\Model */ public function save(Model $model, array $pivotAttributes = [], $touch = true) @@ -698,8 +662,7 @@ class BelongsToMany extends Relation /** * Save an array of new models and attach them to the parent model. * - * @param \Hyperf\Utils\Collection|array $models - * @param array $pivotAttributes + * @param \Hyperf\Utils\Collection|array $models * @return array */ public function saveMany($models, array $pivotAttributes = []) @@ -716,9 +679,7 @@ class BelongsToMany extends Relation /** * Create a new instance of the related model. * - * @param array $attributes - * @param array $joining - * @param bool $touch + * @param bool $touch * @return \Hyperf\Database\Model\Model */ public function create(array $attributes = [], array $joining = [], $touch = true) @@ -738,8 +699,6 @@ class BelongsToMany extends Relation /** * Create an array of new instances of the related models. * - * @param array $records - * @param array $joinings * @return array */ public function createMany(array $records, array $joinings = []) @@ -758,9 +717,7 @@ class BelongsToMany extends Relation /** * Add the constraints for a relationship query. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) @@ -777,16 +734,14 @@ class BelongsToMany extends Relation /** * Add the constraints for a relationship query on the same table. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQueryForSelfJoin(Builder $query, Builder $parentQuery, $columns = ['*']) { $query->select($columns); - $query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash()); + $query->from($this->related->getTable() . ' as ' . $hash = $this->getRelationCountHash()); $this->related->setTable($hash); @@ -812,14 +767,12 @@ class BelongsToMany extends Relation */ public function getRelationCountHash() { - return 'laravel_reserved_'.static::$selfJoinCount++; + return 'laravel_reserved_' . static::$selfJoinCount++; } /** * Specify that the pivot table has creation and update timestamps. * - * @param mixed $createdAt - * @param mixed $updatedAt * @return $this */ public function withTimestamps($createdAt = null, $updatedAt = null) @@ -869,7 +822,7 @@ class BelongsToMany extends Relation */ public function getQualifiedForeignPivotKeyName() { - return $this->table.'.'.$this->foreignPivotKey; + return $this->table . '.' . $this->foreignPivotKey; } /** @@ -889,7 +842,7 @@ class BelongsToMany extends Relation */ public function getQualifiedRelatedPivotKeyName() { - return $this->table.'.'.$this->relatedPivotKey; + return $this->table . '.' . $this->relatedPivotKey; } /** @@ -955,7 +908,7 @@ class BelongsToMany extends Relation /** * Set the join clause for the relation query. * - * @param \Hyperf\Database\Model\Builder|null $query + * @param \Hyperf\Database\Model\Builder|null $query * @return $this */ protected function performJoin($query = null) @@ -967,7 +920,7 @@ class BelongsToMany extends Relation // model instance. Then we can set the "where" for the parent models. $baseTable = $this->related->getTable(); - $key = $baseTable.'.'.$this->relatedKey; + $key = $baseTable . '.' . $this->relatedKey; $query->join($this->table, $key, '=', $this->getQualifiedRelatedPivotKeyName()); @@ -993,7 +946,6 @@ class BelongsToMany extends Relation /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Hyperf\Database\Model\Collection $results * @return array */ protected function buildDictionary(Collection $results) @@ -1013,13 +965,12 @@ class BelongsToMany extends Relation /** * Get the select columns for the relation query. * - * @param array $columns * @return array */ protected function shouldSelect(array $columns = ['*']) { if ($columns == ['*']) { - $columns = [$this->related->getTable().'.*']; + $columns = [$this->related->getTable() . '.*']; } return array_merge($columns, $this->aliasedPivotColumns()); @@ -1037,15 +988,12 @@ class BelongsToMany extends Relation $defaults = [$this->foreignPivotKey, $this->relatedPivotKey]; return collect(array_merge($defaults, $this->pivotColumns))->map(function ($column) { - return $this->table.'.'.$column.' as pivot_'.$column; + return $this->table . '.' . $column . ' as pivot_' . $column; })->unique()->all(); } /** * Hydrate the pivot table relationship on the models. - * - * @param array $models - * @return void */ protected function hydratePivotRelation(array $models) { @@ -1062,7 +1010,6 @@ class BelongsToMany extends Relation /** * Get the pivot attributes from a model. * - * @param \Hyperf\Database\Model\Model $model * @return array */ protected function migratePivotAttributes(Model $model) @@ -1073,7 +1020,7 @@ class BelongsToMany extends Relation // To get the pivots attributes we will just take any of the attributes which // begin with "pivot_" and add those to this arrays, as well as unsetting // them from the parent's models since they exist in a different table. - if (strpos($key, 'pivot_') === 0) { + if (0 === strpos($key, 'pivot_')) { $values[substr($key, 6)] = $value; unset($model->$key); diff --git a/src/database/src/Model/Relations/Concerns/AsPivot.php b/src/database/src/Model/Relations/Concerns/AsPivot.php index b6b791231..1b2a9414a 100644 --- a/src/database/src/Model/Relations/Concerns/AsPivot.php +++ b/src/database/src/Model/Relations/Concerns/AsPivot.php @@ -1,4 +1,5 @@ $ids + * @param array $ids * @return \Hyperf\Database\Model\Builder */ public function newQueryForRestoration($ids) @@ -249,7 +246,6 @@ trait AsPivot /** * Set the keys for a save update query. * - * @param \Hyperf\Database\Model\Builder $query * @return \Hyperf\Database\Model\Builder */ protected function setKeysForSaveQuery(Builder $query) @@ -285,7 +281,7 @@ trait AsPivot /** * Get a new query to restore multiple models by their queueable IDs. * - * @param array|int $ids + * @param array|int $ids * @return \Hyperf\Database\Model\Builder */ protected function newQueryForCollectionRestoration(array $ids) diff --git a/src/database/src/Model/Relations/Concerns/InteractsWithPivotTable.php b/src/database/src/Model/Relations/Concerns/InteractsWithPivotTable.php index b65bb4004..423679e1e 100644 --- a/src/database/src/Model/Relations/Concerns/InteractsWithPivotTable.php +++ b/src/database/src/Model/Relations/Concerns/InteractsWithPivotTable.php @@ -1,4 +1,5 @@ parent->freshTimestamp(); if ($this->using) { - $pivotModel = new $this->using; + $pivotModel = new $this->using(); $fresh = $fresh->format($pivotModel->getDateFormat()); } @@ -457,7 +439,7 @@ trait InteractsWithPivotTable /** * Determine whether the given column is defined as a pivot column. * - * @param string $column + * @param string $column * @return bool */ protected function hasPivotColumn($column) @@ -488,7 +470,6 @@ trait InteractsWithPivotTable /** * Get all of the IDs from the given mixed value. * - * @param mixed $value * @return array */ protected function parseIds($value) @@ -510,9 +491,6 @@ trait InteractsWithPivotTable /** * Get the ID from the given mixed value. - * - * @param mixed $value - * @return mixed */ protected function parseId($value) { @@ -522,7 +500,6 @@ trait InteractsWithPivotTable /** * Cast the given keys to integers if they are numeric and string otherwise. * - * @param array $keys * @return array */ protected function castKeys(array $keys) @@ -534,9 +511,6 @@ trait InteractsWithPivotTable /** * Cast the given key to convert to primary key type. - * - * @param mixed $key - * @return mixed */ protected function castKey($key) { @@ -562,9 +536,7 @@ trait InteractsWithPivotTable /** * Converts a given value to a given type value. * - * @param string $type - * @param mixed $value - * @return mixed + * @param string $type */ protected function getTypeSwapValue($type, $value) { diff --git a/src/database/src/Model/Relations/Concerns/SupportsDefaultModels.php b/src/database/src/Model/Relations/Concerns/SupportsDefaultModels.php index dde63959b..0e7fad304 100644 --- a/src/database/src/Model/Relations/Concerns/SupportsDefaultModels.php +++ b/src/database/src/Model/Relations/Concerns/SupportsDefaultModels.php @@ -1,4 +1,5 @@ setModel(get_class($this->related)); + throw (new ModelNotFoundException())->setModel(get_class($this->related)); } /** * Find a related model by its primary key. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|null */ public function find($id, $columns = ['*']) @@ -271,8 +255,7 @@ class HasManyThrough extends Relation /** * Find multiple related models by their primary keys. * - * @param mixed $ids - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection */ public function findMany($ids, $columns = ['*']) @@ -290,8 +273,7 @@ class HasManyThrough extends Relation /** * Find a related model by its primary key or throw an exception. * - * @param mixed $id - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection * * @throws \Hyperf\Database\Model\ModelNotFoundException @@ -308,13 +290,11 @@ class HasManyThrough extends Relation return $result; } - throw (new ModelNotFoundException)->setModel(get_class($this->related), $id); + throw (new ModelNotFoundException())->setModel(get_class($this->related), $id); } /** * Get the results of the relationship. - * - * @return mixed */ public function getResults() { @@ -324,7 +304,7 @@ class HasManyThrough extends Relation /** * Execute the query as a "select" statement. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Collection */ public function get($columns = ['*']) @@ -346,10 +326,10 @@ class HasManyThrough extends Relation /** * Get a paginator for the "select" statement. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int $page * @return \Hyperf\Contracts\Pagination\LengthAwarePaginator */ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) @@ -362,10 +342,10 @@ class HasManyThrough extends Relation /** * Paginate the given query into a simple paginator. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page * @return \Hyperf\Contracts\Pagination\Paginator */ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) @@ -379,7 +359,6 @@ class HasManyThrough extends Relation * Chunk the results of the query. * * @param int $count - * @param callable $callback * @return bool */ public function chunk($count, callable $callback) @@ -400,7 +379,6 @@ class HasManyThrough extends Relation /** * Execute a callback over each item while chunking. * - * @param callable $callback * @param int $count * @return bool */ @@ -408,7 +386,7 @@ class HasManyThrough extends Relation { return $this->chunk($count, function ($results) use ($callback) { foreach ($results as $key => $value) { - if ($callback($value, $key) === false) { + if (false === $callback($value, $key)) { return false; } } @@ -418,9 +396,7 @@ class HasManyThrough extends Relation /** * Add the constraints for a relationship query. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) @@ -445,16 +421,14 @@ class HasManyThrough extends Relation /** * Add the constraints for a relationship query on the same table. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) { - $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()); + $query->from($query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash()); - $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondKey); + $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash . '.' . $this->secondKey); if ($this->throughParentSoftDeletes()) { $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn()); @@ -463,7 +437,7 @@ class HasManyThrough extends Relation $query->getModel()->setTable($hash); return $query->select($columns)->whereColumn( - $parentQuery->getQuery()->from.'.'.$this->localKey, + $parentQuery->getQuery()->from . '.' . $this->localKey, '=', $this->getQualifiedFirstKeyName() ); @@ -472,25 +446,23 @@ class HasManyThrough extends Relation /** * Add the constraints for a relationship query on the same table as the through parent. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQueryForThroughSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) { - $table = $this->throughParent->getTable().' as '.$hash = $this->getRelationCountHash(); + $table = $this->throughParent->getTable() . ' as ' . $hash = $this->getRelationCountHash(); - $query->join($table, $hash.'.'.$this->secondLocalKey, '=', $this->getQualifiedFarKeyName()); + $query->join($table, $hash . '.' . $this->secondLocalKey, '=', $this->getQualifiedFarKeyName()); if ($this->throughParentSoftDeletes()) { - $query->whereNull($hash.'.'.$this->throughParent->getDeletedAtColumn()); + $query->whereNull($hash . '.' . $this->throughParent->getDeletedAtColumn()); } return $query->select($columns)->whereColumn( - $parentQuery->getQuery()->from.'.'.$this->localKey, + $parentQuery->getQuery()->from . '.' . $this->localKey, '=', - $hash.'.'.$this->firstKey + $hash . '.' . $this->firstKey ); } @@ -501,7 +473,7 @@ class HasManyThrough extends Relation */ public function getRelationCountHash() { - return 'laravel_reserved_'.static::$selfJoinCount++; + return 'laravel_reserved_' . static::$selfJoinCount++; } /** @@ -586,9 +558,6 @@ class HasManyThrough extends Relation /** * Set the join clause on the query. - * - * @param \Hyperf\Database\Model\Builder|null $query - * @return void */ protected function performJoin(Builder $query = null) { @@ -606,7 +575,6 @@ class HasManyThrough extends Relation /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Hyperf\Database\Model\Collection $results * @return array */ protected function buildDictionary(Collection $results) @@ -626,22 +594,21 @@ class HasManyThrough extends Relation /** * Set the select clause for the relation query. * - * @param array $columns * @return array */ protected function shouldSelect(array $columns = ['*']) { if ($columns == ['*']) { - $columns = [$this->related->getTable().'.*']; + $columns = [$this->related->getTable() . '.*']; } - return array_merge($columns, [$this->getQualifiedFirstKeyName().' as laravel_through_key']); + return array_merge($columns, [$this->getQualifiedFirstKeyName() . ' as laravel_through_key']); } /** * Prepare the query builder for query execution. * - * @param array $columns + * @param array $columns * @return \Hyperf\Database\Model\Builder */ protected function prepareQueryBuilder($columns = ['*']) diff --git a/src/database/src/Model/Relations/HasOne.php b/src/database/src/Model/Relations/HasOne.php index d6776ffe4..e66342396 100755 --- a/src/database/src/Model/Relations/HasOne.php +++ b/src/database/src/Model/Relations/HasOne.php @@ -1,4 +1,5 @@ from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()); + $query->from($query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash()); $query->getModel()->setTable($hash); return $query->select($columns)->whereColumn( $this->getQualifiedParentKeyName(), '=', - $hash.'.'.$this->getForeignKeyName() + $hash . '.' . $this->getForeignKeyName() ); } @@ -312,7 +285,7 @@ abstract class HasOneOrMany extends Relation */ public function getRelationCountHash() { - return 'laravel_reserved_'.static::$selfJoinCount++; + return 'laravel_reserved_' . static::$selfJoinCount++; } /** @@ -327,8 +300,6 @@ abstract class HasOneOrMany extends Relation /** * Get the key value of the parent's local key. - * - * @return mixed */ public function getParentKey() { @@ -380,10 +351,8 @@ abstract class HasOneOrMany extends Relation /** * Match the eagerly loaded results to their many parents. * - * @param array $models - * @param \Hyperf\Database\Model\Collection $results - * @param string $relation - * @param string $type + * @param string $relation + * @param string $type * @return array */ protected function matchOneOrMany(array $models, Collection $results, $relation, $type) @@ -408,22 +377,19 @@ abstract class HasOneOrMany extends Relation /** * Get the value of a relationship by one or many type. * - * @param array $dictionary - * @param string $key - * @param string $type - * @return mixed + * @param string $key + * @param string $type */ protected function getRelationValue(array $dictionary, $key, $type) { $value = $dictionary[$key]; - return $type === 'one' ? reset($value) : $this->related->newCollection($value); + return 'one' === $type ? reset($value) : $this->related->newCollection($value); } /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Hyperf\Database\Model\Collection $results * @return array */ protected function buildDictionary(Collection $results) @@ -437,9 +403,6 @@ abstract class HasOneOrMany extends Relation /** * Set the foreign ID for creating a related model. - * - * @param \Hyperf\Database\Model\Model $model - * @return void */ protected function setForeignAttributesForCreate(Model $model) { diff --git a/src/database/src/Model/Relations/HasOneThrough.php b/src/database/src/Model/Relations/HasOneThrough.php index 27c367598..81455b50d 100644 --- a/src/database/src/Model/Relations/HasOneThrough.php +++ b/src/database/src/Model/Relations/HasOneThrough.php @@ -1,4 +1,5 @@ $ids + * @param array $ids * @return \Hyperf\Database\Model\Builder */ protected function newQueryForCollectionRestoration(array $ids) diff --git a/src/database/src/Model/Relations/MorphTo.php b/src/database/src/Model/Relations/MorphTo.php index 3a4e59342..25fd534c7 100644 --- a/src/database/src/Model/Relations/MorphTo.php +++ b/src/database/src/Model/Relations/MorphTo.php @@ -1,4 +1,5 @@ with($this->getQuery()->getEagerLoads()); return $query->whereIn( - $instance->getTable().'.'.$ownerKey, + $instance->getTable() . '.' . $ownerKey, $this->gatherKeysByType($type) )->get(); } @@ -263,7 +246,7 @@ class MorphTo extends BelongsTo /** * Gather all of the foreign keys for a given type. * - * @param string $type + * @param string $type * @return array */ protected function gatherKeysByType($type) @@ -276,9 +259,7 @@ class MorphTo extends BelongsTo /** * Match the results for a given type to their parents. * - * @param string $type - * @param \Hyperf\Database\Model\Collection $results - * @return void + * @param string $type */ protected function matchToMorphParents($type, Collection $results) { @@ -296,7 +277,6 @@ class MorphTo extends BelongsTo /** * Replay stored macro calls on the actual related instance. * - * @param \Hyperf\Database\Model\Builder $query * @return \Hyperf\Database\Model\Builder */ protected function replayMacros(Builder $query) diff --git a/src/database/src/Model/Relations/MorphToMany.php b/src/database/src/Model/Relations/MorphToMany.php index ad7e4eeac..1b26be557 100644 --- a/src/database/src/Model/Relations/MorphToMany.php +++ b/src/database/src/Model/Relations/MorphToMany.php @@ -1,4 +1,5 @@ inverse = $inverse; - $this->morphType = $name.'_type'; + $this->morphType = $name . '_type'; $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); parent::__construct( @@ -85,29 +83,24 @@ class MorphToMany extends BelongsToMany /** * Set the constraints for an eager load of the relation. - * - * @param array $models - * @return void */ public function addEagerConstraints(array $models) { parent::addEagerConstraints($models); - $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + $this->query->where($this->table . '.' . $this->morphType, $this->morphClass); } /** * Add the constraints for a relationship count query. * - * @param \Hyperf\Database\Model\Builder $query - * @param \Hyperf\Database\Model\Builder $parentQuery - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Database\Model\Builder */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) { return parent::getRelationExistenceQuery($query, $parentQuery, $columns)->where( - $this->table.'.'.$this->morphType, + $this->table . '.' . $this->morphType, $this->morphClass ); } @@ -115,8 +108,7 @@ class MorphToMany extends BelongsToMany /** * Create a new pivot model instance. * - * @param array $attributes - * @param bool $exists + * @param bool $exists * @return \Hyperf\Database\Model\Relations\Pivot */ public function newPivot(array $attributes = [], $exists = false) @@ -172,7 +164,7 @@ class MorphToMany extends BelongsToMany { parent::addWhereConstraints(); - $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + $this->query->where($this->table . '.' . $this->morphType, $this->morphClass); return $this; } @@ -215,7 +207,7 @@ class MorphToMany extends BelongsToMany $defaults = [$this->foreignPivotKey, $this->relatedPivotKey, $this->morphType]; return collect(array_merge($defaults, $this->pivotColumns))->map(function ($column) { - return $this->table.'.'.$column.' as pivot_'.$column; + return $this->table . '.' . $column . ' as pivot_' . $column; })->unique()->all(); } } diff --git a/src/database/src/Model/Relations/Pivot.php b/src/database/src/Model/Relations/Pivot.php index 96660c6f5..498562de4 100755 --- a/src/database/src/Model/Relations/Pivot.php +++ b/src/database/src/Model/Relations/Pivot.php @@ -1,4 +1,5 @@ getTable(); + return (new $model())->getTable(); }, $models), $models); } } diff --git a/src/database/src/Model/Scope.php b/src/database/src/Model/Scope.php index 85f4e2e08..dab9f24fb 100644 --- a/src/database/src/Model/Scope.php +++ b/src/database/src/Model/Scope.php @@ -1,4 +1,5 @@ fireModelEvent('restoring') === false) { + if (false === $this->fireModelEvent('restoring')) { return false; } @@ -89,8 +88,7 @@ trait SoftDeletes /** * Register a restoring model event with the dispatcher. * - * @param \Closure|string $callback - * @return void + * @param \Closure|string $callback */ public static function restoring($callback) { @@ -100,8 +98,7 @@ trait SoftDeletes /** * Register a restored model event with the dispatcher. * - * @param \Closure|string $callback - * @return void + * @param \Closure|string $callback */ public static function restored($callback) { @@ -140,8 +137,6 @@ trait SoftDeletes /** * Perform the actual delete query on this model instance. - * - * @return mixed */ protected function performDeleteOnModel() { @@ -156,8 +151,6 @@ trait SoftDeletes /** * Perform the actual delete query on this model instance. - * - * @return void */ protected function runSoftDelete() { diff --git a/src/database/src/Model/SoftDeletingScope.php b/src/database/src/Model/SoftDeletingScope.php index 69e620d76..25c4cdcf2 100644 --- a/src/database/src/Model/SoftDeletingScope.php +++ b/src/database/src/Model/SoftDeletingScope.php @@ -1,4 +1,5 @@ withTablePrefix(new QueryGrammar); + return $this->withTablePrefix(new QueryGrammar()); } /** @@ -63,7 +64,7 @@ class MySqlConnection extends Connection */ protected function getDefaultSchemaGrammar() { - return $this->withTablePrefix(new SchemaGrammar); + return $this->withTablePrefix(new SchemaGrammar()); } /** @@ -73,7 +74,7 @@ class MySqlConnection extends Connection */ protected function getDefaultPostProcessor() { - return new MySqlProcessor; + return new MySqlProcessor(); } /** @@ -83,6 +84,6 @@ class MySqlConnection extends Connection */ protected function getDoctrineDriver() { - return new DoctrineDriver; + return new DoctrineDriver(); } } diff --git a/src/database/src/Query/Builder.php b/src/database/src/Query/Builder.php index 2fde13324..53268d760 100755 --- a/src/database/src/Query/Builder.php +++ b/src/database/src/Query/Builder.php @@ -1,4 +1,5 @@ connection = $connection; - $this->grammar = $grammar ? : $connection->getQueryGrammar(); - $this->processor = $processor ? : $connection->getPostProcessor(); + $this->grammar = $grammar ?: $connection->getQueryGrammar(); + $this->processor = $processor ?: $connection->getPostProcessor(); } /** * Handle dynamic method calls into the method. * - * @param string $method - * @param array $parameters - * @return mixed + * @param string $method + * @param array $parameters * @throws \BadMethodCallException */ public function __call($method, $parameters) @@ -285,7 +283,7 @@ class Builder * Add a subselect expression to the query. * * @param \Closure|\Hyperf\Database\Query\Builder|string $query - * @param string $as + * @param string $as * @return \Hyperf\Database\Query\Builder|static * @throws \InvalidArgumentException */ @@ -299,8 +297,7 @@ class Builder /** * Add a new "raw" select expression to the query. * - * @param string $expression - * @param array $bindings + * @param string $expression * @return \Hyperf\Database\Query\Builder|static */ public function selectRaw($expression, array $bindings = []) @@ -318,7 +315,7 @@ class Builder * Makes "from" fetch from a subquery. * * @param \Closure|\Hyperf\Database\Query\Builder|string $query - * @param string $as + * @param string $as * @return \Hyperf\Database\Query\Builder|static * @throws \InvalidArgumentException */ @@ -332,8 +329,7 @@ class Builder /** * Add a raw from clause to the query. * - * @param string $expression - * @param mixed $bindings + * @param string $expression * @return \Hyperf\Database\Query\Builder|static */ public function fromRaw($expression, $bindings = []) @@ -355,7 +351,7 @@ class Builder { $column = is_array($column) ? $column : func_get_args(); - $this->columns = array_merge((array)$this->columns, $column); + $this->columns = array_merge((array) $this->columns, $column); return $this; } @@ -388,12 +384,12 @@ class Builder /** * Add a join clause to the query. * - * @param string $table + * @param string $table * @param \Closure|string $first - * @param string|null $operator - * @param string|null $second - * @param string $type - * @param bool $where + * @param string|null $operator + * @param string|null $second + * @param string $type + * @param bool $where * @return $this */ public function join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false) @@ -428,11 +424,11 @@ class Builder /** * Add a "join where" clause to the query. * - * @param string $table - * @param \Closure|string $first - * @param string $operator - * @param string $second - * @param string $type + * @param string $table + * @param \Closure|string $first + * @param string $operator + * @param string $second + * @param string $type * @return \Hyperf\Database\Query\Builder|static */ public function joinWhere($table, $first, $operator, $second, $type = 'inner') @@ -444,12 +440,12 @@ class Builder * Add a subquery join clause to the query. * * @param \Closure|\Hyperf\Database\Query\Builder|string $query - * @param string $as - * @param \Closure|string $first - * @param string|null $operator - * @param string|null $second - * @param string $type - * @param bool $where + * @param string $as + * @param \Closure|string $first + * @param string|null $operator + * @param string|null $second + * @param string $type + * @param bool $where * @return \Hyperf\Database\Query\Builder|static * @throws \InvalidArgumentException */ @@ -467,10 +463,10 @@ class Builder /** * Add a left join to the query. * - * @param string $table - * @param \Closure|string $first - * @param string|null $operator - * @param string|null $second + * @param string $table + * @param \Closure|string $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function leftJoin($table, $first, $operator = null, $second = null) @@ -481,10 +477,10 @@ class Builder /** * Add a "join where" clause to the query. * - * @param string $table - * @param string $first - * @param string $operator - * @param string $second + * @param string $table + * @param string $first + * @param string $operator + * @param string $second * @return \Hyperf\Database\Query\Builder|static */ public function leftJoinWhere($table, $first, $operator, $second) @@ -496,10 +492,10 @@ class Builder * Add a subquery left join to the query. * * @param \Closure|\Hyperf\Database\Query\Builder|string $query - * @param string $as - * @param string $first - * @param string|null $operator - * @param string|null $second + * @param string $as + * @param string $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function leftJoinSub($query, $as, $first, $operator = null, $second = null) @@ -510,10 +506,10 @@ class Builder /** * Add a right join to the query. * - * @param string $table - * @param \Closure|string $first - * @param string|null $operator - * @param string|null $second + * @param string $table + * @param \Closure|string $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function rightJoin($table, $first, $operator = null, $second = null) @@ -524,10 +520,10 @@ class Builder /** * Add a "right join where" clause to the query. * - * @param string $table - * @param string $first - * @param string $operator - * @param string $second + * @param string $table + * @param string $first + * @param string $operator + * @param string $second * @return \Hyperf\Database\Query\Builder|static */ public function rightJoinWhere($table, $first, $operator, $second) @@ -539,10 +535,10 @@ class Builder * Add a subquery right join to the query. * * @param \Closure|\Hyperf\Database\Query\Builder|string $query - * @param string $as - * @param string $first - * @param string|null $operator - * @param string|null $second + * @param string $as + * @param string $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function rightJoinSub($query, $as, $first, $operator = null, $second = null) @@ -553,10 +549,10 @@ class Builder /** * Add a "cross join" clause to the query. * - * @param string $table - * @param \Closure|string|null $first - * @param string|null $operator - * @param string|null $second + * @param string $table + * @param \Closure|string|null $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function crossJoin($table, $first = null, $operator = null, $second = null) @@ -573,24 +569,21 @@ class Builder /** * Merge an array of where clauses and bindings. * - * @param array $wheres - * @param array $bindings - * @return void + * @param array $wheres + * @param array $bindings */ public function mergeWheres($wheres, $bindings) { - $this->wheres = array_merge($this->wheres, (array)$wheres); + $this->wheres = array_merge($this->wheres, (array) $wheres); - $this->bindings['where'] = array_values(array_merge($this->bindings['where'], (array)$bindings)); + $this->bindings['where'] = array_values(array_merge($this->bindings['where'], (array) $bindings)); } /** * Add a basic where clause to the query. * * @param string|array|\Closure $column - * @param mixed $operator - * @param mixed $value - * @param string $boolean + * @param string $boolean * @return $this */ public function where($column, $operator = null, $value = null, $boolean = 'and') @@ -605,7 +598,7 @@ class Builder // Here we will make some assumptions about the operator. If only 2 values are // passed to the method, we will assume that the operator is an equals sign // and keep going. Otherwise, we'll require the operator to be passed in. - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); // If the columns is actually a Closure instance, we will assume the developer // wants to begin a nested where statement which is wrapped in parenthesis. @@ -632,7 +625,7 @@ class Builder // where null clause to the query. So, we will allow a short-cut here to // that method for convenience so the developer doesn't have to check. if (is_null($value)) { - return $this->whereNull($column, $boolean, $operator !== '='); + return $this->whereNull($column, $boolean, '=' !== $operator); } // If the column is making a JSON reference we'll check to see if the value @@ -659,9 +652,9 @@ class Builder /** * Prepare the value and operator for a where clause. * - * @param string $value - * @param string $operator - * @param bool $useDefault + * @param string $value + * @param string $operator + * @param bool $useDefault * @return array * @throws \InvalidArgumentException */ @@ -679,14 +672,12 @@ class Builder /** * Add an "or where" clause to the query. * - * @param string|array|\Closure $column - * @param mixed $operator - * @param mixed $value + * @param string|array|\Closure $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhere($column, $operator = null, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->where($column, $operator, $value, 'or'); } @@ -694,10 +685,10 @@ class Builder /** * Add a "where" clause comparing two columns to the query. * - * @param string|array $first - * @param string|null $operator - * @param string|null $second - * @param string|null $boolean + * @param string|array $first + * @param string|null $operator + * @param string|null $second + * @param string|null $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereColumn($first, $operator = null, $second = null, $boolean = 'and') @@ -729,9 +720,9 @@ class Builder /** * Add an "or where" clause comparing two columns to the query. * - * @param string|array $first - * @param string|null $operator - * @param string|null $second + * @param string|array $first + * @param string|null $operator + * @param string|null $second * @return \Hyperf\Database\Query\Builder|static */ public function orWhereColumn($first, $operator = null, $second = null) @@ -743,7 +734,6 @@ class Builder * Add a raw where clause to the query. * * @param string $sql - * @param mixed $bindings * @param string $boolean * @return $this */ @@ -751,7 +741,7 @@ class Builder { $this->wheres[] = ['type' => 'raw', 'sql' => $sql, 'boolean' => $boolean]; - $this->addBinding((array)$bindings, 'where'); + $this->addBinding((array) $bindings, 'where'); return $this; } @@ -759,8 +749,7 @@ class Builder /** * Add a raw or where clause to the query. * - * @param string $sql - * @param mixed $bindings + * @param string $sql * @return \Hyperf\Database\Query\Builder|static */ public function orWhereRaw($sql, $bindings = []) @@ -772,9 +761,8 @@ class Builder * Add a "where in" clause to the query. * * @param string $column - * @param mixed $values * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ public function whereIn($column, $values, $boolean = 'and', $not = false) @@ -812,8 +800,7 @@ class Builder /** * Add an "or where in" clause to the query. * - * @param string $column - * @param mixed $values + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereIn($column, $values) @@ -824,9 +811,8 @@ class Builder /** * Add a "where not in" clause to the query. * - * @param string $column - * @param mixed $values - * @param string $boolean + * @param string $column + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereNotIn($column, $values, $boolean = 'and') @@ -837,8 +823,7 @@ class Builder /** * Add an "or where not in" clause to the query. * - * @param string $column - * @param mixed $values + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereNotIn($column, $values) @@ -849,10 +834,10 @@ class Builder /** * Add a "where in raw" clause for integer values to the query. * - * @param string $column + * @param string $column * @param \Hyperf\Contracts\Support\Arrayable|array $values - * @param string $boolean - * @param bool $not + * @param string $boolean + * @param bool $not * @return $this */ public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = false) @@ -864,7 +849,7 @@ class Builder } foreach ($values as &$value) { - $value = (int)$value; + $value = (int) $value; } $this->wheres[] = compact('type', 'column', 'values', 'boolean'); @@ -875,9 +860,9 @@ class Builder /** * Add a "where not in raw" clause for integer values to the query. * - * @param string $column + * @param string $column * @param \Hyperf\Contracts\Support\Arrayable|array $values - * @param string $boolean + * @param string $boolean * @return $this */ public function whereIntegerNotInRaw($column, $values, $boolean = 'and') @@ -890,7 +875,7 @@ class Builder * * @param string $column * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ public function whereNull($column, $boolean = 'and', $not = false) @@ -905,7 +890,7 @@ class Builder /** * Add an "or where null" clause to the query. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereNull($column) @@ -916,8 +901,8 @@ class Builder /** * Add a "where not null" clause to the query. * - * @param string $column - * @param string $boolean + * @param string $column + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereNotNull($column, $boolean = 'and') @@ -929,9 +914,8 @@ class Builder * Add a where between statement to the query. * * @param string $column - * @param array $values * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ public function whereBetween($column, array $values, $boolean = 'and', $not = false) @@ -948,8 +932,7 @@ class Builder /** * Add an or where between statement to the query. * - * @param string $column - * @param array $values + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereBetween($column, array $values) @@ -960,9 +943,8 @@ class Builder /** * Add a where not between statement to the query. * - * @param string $column - * @param array $values - * @param string $boolean + * @param string $column + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereNotBetween($column, array $values, $boolean = 'and') @@ -973,8 +955,7 @@ class Builder /** * Add an or where not between statement to the query. * - * @param string $column - * @param array $values + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereNotBetween($column, array $values) @@ -985,7 +966,7 @@ class Builder /** * Add an "or where not null" clause to the query. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function orWhereNotNull($column) @@ -996,15 +977,15 @@ class Builder /** * Add a "where date" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereDate($column, $operator, $value = null, $boolean = 'and') { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); if ($value instanceof DateTimeInterface) { $value = $value->format('Y-m-d'); @@ -1016,14 +997,14 @@ class Builder /** * Add an "or where date" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value * @return \Hyperf\Database\Query\Builder|static */ public function orWhereDate($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->whereDate($column, $operator, $value, 'or'); } @@ -1031,15 +1012,15 @@ class Builder /** * Add a "where time" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereTime($column, $operator, $value = null, $boolean = 'and') { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); if ($value instanceof DateTimeInterface) { $value = $value->format('H:i:s'); @@ -1051,14 +1032,14 @@ class Builder /** * Add an "or where time" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value * @return \Hyperf\Database\Query\Builder|static */ public function orWhereTime($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->whereTime($column, $operator, $value, 'or'); } @@ -1066,15 +1047,15 @@ class Builder /** * Add a "where day" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereDay($column, $operator, $value = null, $boolean = 'and') { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); if ($value instanceof DateTimeInterface) { $value = $value->format('d'); @@ -1086,14 +1067,14 @@ class Builder /** * Add an "or where day" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value * @return \Hyperf\Database\Query\Builder|static */ public function orWhereDay($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->addDateBasedWhere('Day', $column, $operator, $value, 'or'); } @@ -1101,15 +1082,15 @@ class Builder /** * Add a "where month" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereMonth($column, $operator, $value = null, $boolean = 'and') { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); if ($value instanceof DateTimeInterface) { $value = $value->format('m'); @@ -1121,14 +1102,14 @@ class Builder /** * Add an "or where month" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string $value + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string $value * @return \Hyperf\Database\Query\Builder|static */ public function orWhereMonth($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->addDateBasedWhere('Month', $column, $operator, $value, 'or'); } @@ -1136,15 +1117,15 @@ class Builder /** * Add a "where year" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string|int $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string|int $value + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereYear($column, $operator, $value = null, $boolean = 'and') { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); if ($value instanceof DateTimeInterface) { $value = $value->format('Y'); @@ -1156,14 +1137,14 @@ class Builder /** * Add an "or where year" statement to the query. * - * @param string $column - * @param string $operator - * @param \DateTimeInterface|string|int $value + * @param string $column + * @param string $operator + * @param \DateTimeInterface|string|int $value * @return \Hyperf\Database\Query\Builder|static */ public function orWhereYear($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->addDateBasedWhere('Year', $column, $operator, $value, 'or'); } @@ -1171,8 +1152,7 @@ class Builder /** * Add a nested where statement to the query. * - * @param \Closure $callback - * @param string $boolean + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereNested(Closure $callback, $boolean = 'and') @@ -1196,7 +1176,7 @@ class Builder * Add another query builder as a nested where to the query builder. * * @param \Hyperf\Database\Query\Builder|static $query - * @param string $boolean + * @param string $boolean * @return $this */ public function addNestedWhereQuery($query, $boolean = 'and') @@ -1215,9 +1195,8 @@ class Builder /** * Add an exists clause to the query. * - * @param \Closure $callback * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ public function whereExists(Closure $callback, $boolean = 'and', $not = false) @@ -1235,8 +1214,7 @@ class Builder /** * Add an or exists clause to the query. * - * @param \Closure $callback - * @param bool $not + * @param bool $not * @return \Hyperf\Database\Query\Builder|static */ public function orWhereExists(Closure $callback, $not = false) @@ -1247,8 +1225,7 @@ class Builder /** * Add a where not exists clause to the query. * - * @param \Closure $callback - * @param string $boolean + * @param string $boolean * @return \Hyperf\Database\Query\Builder|static */ public function whereNotExists(Closure $callback, $boolean = 'and') @@ -1259,7 +1236,6 @@ class Builder /** * Add a where not exists clause to the query. * - * @param \Closure $callback * @return \Hyperf\Database\Query\Builder|static */ public function orWhereNotExists(Closure $callback) @@ -1271,8 +1247,8 @@ class Builder * Add an exists clause to the query. * * @param \Hyperf\Database\Query\Builder $query - * @param string $boolean - * @param bool $not + * @param string $boolean + * @param bool $not * @return $this */ public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false) @@ -1289,9 +1265,9 @@ class Builder /** * Adds a where condition using row values. * - * @param array $columns + * @param array $columns * @param string $operator - * @param array $values + * @param array $values * @param string $boolean * @return $this */ @@ -1313,9 +1289,9 @@ class Builder /** * Adds a or where condition using row values. * - * @param array $columns + * @param array $columns * @param string $operator - * @param array $values + * @param array $values * @return $this */ public function orWhereRowValues($columns, $operator, $values) @@ -1327,9 +1303,8 @@ class Builder * Add a "where JSON contains" clause to the query. * * @param string $column - * @param mixed $value * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ public function whereJsonContains($column, $value, $boolean = 'and', $not = false) @@ -1349,7 +1324,6 @@ class Builder * Add a "or where JSON contains" clause to the query. * * @param string $column - * @param mixed $value * @return $this */ public function orWhereJsonContains($column, $value) @@ -1361,7 +1335,6 @@ class Builder * Add a "where JSON not contains" clause to the query. * * @param string $column - * @param mixed $value * @param string $boolean * @return $this */ @@ -1374,7 +1347,6 @@ class Builder * Add a "or where JSON not contains" clause to the query. * * @param string $column - * @param mixed $value * @return $this */ public function orWhereJsonDoesntContain($column, $value) @@ -1386,8 +1358,6 @@ class Builder * Add a "where JSON length" clause to the query. * * @param string $column - * @param mixed $operator - * @param mixed $value * @param string $boolean * @return $this */ @@ -1395,7 +1365,7 @@ class Builder { $type = 'JsonLength'; - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean'); @@ -1410,13 +1380,11 @@ class Builder * Add a "or where JSON length" clause to the query. * * @param string $column - * @param mixed $operator - * @param mixed $value * @return $this */ public function orWhereJsonLength($column, $operator, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->whereJsonLength($column, $operator, $value, 'or'); } @@ -1445,10 +1413,10 @@ class Builder // If the segment is not a boolean connector, we can assume it is a column's name // and we will add it to the query as a new constraint as a where clause, then // we can keep iterating through the dynamic method string's segments again. - if ($segment !== 'And' && $segment !== 'Or') { + if ('And' !== $segment && 'Or' !== $segment) { $this->addDynamic($segment, $connector, $parameters, $index); - $index++; + ++$index; } // Otherwise, we will store the connector so we know how the next where clause we @@ -1470,7 +1438,7 @@ class Builder public function groupBy(...$groups) { foreach ($groups as $group) { - $this->groups = array_merge((array)$this->groups, Arr::wrap($group)); + $this->groups = array_merge((array) $this->groups, Arr::wrap($group)); } return $this; @@ -1479,10 +1447,10 @@ class Builder /** * Add a "having" clause to the query. * - * @param string $column + * @param string $column * @param string|null $operator * @param string|null $value - * @param string $boolean + * @param string $boolean * @return $this */ public function having($column, $operator = null, $value = null, $boolean = 'and') @@ -1492,7 +1460,7 @@ class Builder // Here we will make some assumptions about the operator. If only 2 values are // passed to the method, we will assume that the operator is an equals sign // and keep going. Otherwise, we'll require the operator to be passed in. - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); // If the given operator is not found in the list of valid operators we will // assume that the developer is just short-cutting the '=' operators and @@ -1513,14 +1481,14 @@ class Builder /** * Add a "or having" clause to the query. * - * @param string $column - * @param string|null $operator - * @param string|null $value + * @param string $column + * @param string|null $operator + * @param string|null $value * @return \Hyperf\Database\Query\Builder|static */ public function orHaving($column, $operator = null, $value = null) { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator($value, $operator, 2 === func_num_args()); return $this->having($column, $operator, $value, 'or'); } @@ -1528,10 +1496,9 @@ class Builder /** * Add a "having between " clause to the query. * - * @param string $column - * @param array $values - * @param string $boolean - * @param bool $not + * @param string $column + * @param string $boolean + * @param bool $not * @return \Hyperf\Database\Query\Builder|static */ public function havingBetween($column, array $values, $boolean = 'and', $not = false) @@ -1549,7 +1516,6 @@ class Builder * Add a raw having clause to the query. * * @param string $sql - * @param array $bindings * @param string $boolean * @return $this */ @@ -1567,8 +1533,7 @@ class Builder /** * Add a raw or having clause to the query. * - * @param string $sql - * @param array $bindings + * @param string $sql * @return \Hyperf\Database\Query\Builder|static */ public function orHavingRaw($sql, array $bindings = []) @@ -1587,7 +1552,7 @@ class Builder { $this->{$this->unions ? 'unionOrders' : 'orders'}[] = [ 'column' => $column, - 'direction' => strtolower($direction) === 'asc' ? 'asc' : 'desc', + 'direction' => 'asc' === strtolower($direction) ? 'asc' : 'desc', ]; return $this; @@ -1607,7 +1572,7 @@ class Builder /** * Add an "order by" clause for a timestamp to the query. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function latest($column = 'created_at') @@ -1618,7 +1583,7 @@ class Builder /** * Add an "order by" clause for a timestamp to the query. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function oldest($column = 'created_at') @@ -1641,7 +1606,7 @@ class Builder * Add a raw "order by" clause to the query. * * @param string $sql - * @param array $bindings + * @param array $bindings * @return $this */ public function orderByRaw($sql, $bindings = []) @@ -1658,7 +1623,7 @@ class Builder /** * Alias to set the "offset" value of the query. * - * @param int $value + * @param int $value * @return \Hyperf\Database\Query\Builder|static */ public function skip($value) @@ -1669,7 +1634,7 @@ class Builder /** * Set the "offset" value of the query. * - * @param int $value + * @param int $value * @return $this */ public function offset($value) @@ -1684,7 +1649,7 @@ class Builder /** * Alias to set the "limit" value of the query. * - * @param int $value + * @param int $value * @return \Hyperf\Database\Query\Builder|static */ public function take($value) @@ -1695,7 +1660,7 @@ class Builder /** * Set the "limit" value of the query. * - * @param int $value + * @param int $value * @return $this */ public function limit($value) @@ -1712,8 +1677,8 @@ class Builder /** * Set the limit and offset for a given page. * - * @param int $page - * @param int $perPage + * @param int $page + * @param int $perPage * @return \Hyperf\Database\Query\Builder|static */ public function forPage($page, $perPage = 15) @@ -1724,9 +1689,9 @@ class Builder /** * Constrain the query to the next "page" of results after a given ID. * - * @param int $perPage - * @param int|null $lastId - * @param string $column + * @param int $perPage + * @param int|null $lastId + * @param string $column * @return \Hyperf\Database\Query\Builder|static */ public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id') @@ -1744,7 +1709,7 @@ class Builder * Add a union statement to the query. * * @param \Hyperf\Database\Query\Builder|\Closure $query - * @param bool $all + * @param bool $all * @return \Hyperf\Database\Query\Builder|static */ public function union($query, $all = false) @@ -1821,8 +1786,8 @@ class Builder /** * Execute a query for a single record by ID. * - * @param int $id - * @param array $columns + * @param int $id + * @param array $columns * @return mixed|static */ public function find($id, $columns = ['*']) @@ -1833,12 +1798,11 @@ class Builder /** * Get a single column's value from the first result of a query. * - * @param string $column - * @return mixed + * @param string $column */ public function value($column) { - $result = (array)$this->first([$column]); + $result = (array) $this->first([$column]); return count($result) > 0 ? reset($result) : null; } @@ -1846,7 +1810,7 @@ class Builder /** * Execute the query as a "select" statement. * - * @param array|string $columns + * @param array|string $columns */ public function get($columns = ['*']): Collection { @@ -1858,14 +1822,14 @@ class Builder /** * Paginate the given query into a simple paginator. * - * @param int $perPage - * @param array $columns - * @param string $pageName - * @param int|null $page + * @param int $perPage + * @param array $columns + * @param string $pageName + * @param int|null $page */ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null): PaginatorInterface { - $page = $page ? : Paginator::resolveCurrentPage($pageName); + $page = $page ?: Paginator::resolveCurrentPage($pageName); $this->skip(($page - 1) * $perPage)->take($perPage + 1); @@ -1893,10 +1857,10 @@ class Builder } elseif (! isset($results[0])) { return 0; } elseif (is_object($results[0])) { - return (int)$results[0]->aggregate; + return (int) $results[0]->aggregate; } - return (int)array_change_key_case((array)$results[0])['aggregate']; + return (int) array_change_key_case((array) $results[0])['aggregate']; } /** @@ -1916,15 +1880,14 @@ class Builder /** * Chunk the results of a query by comparing numeric IDs. * - * @param int $count - * @param callable $callback - * @param string $column + * @param int $count + * @param string $column * @param string|null $alias * @return bool */ public function chunkById($count, callable $callback, $column = 'id', $alias = null) { - $alias = $alias ? : $column; + $alias = $alias ?: $column; $lastId = null; @@ -1938,14 +1901,14 @@ class Builder $countResults = $results->count(); - if ($countResults == 0) { + if (0 == $countResults) { break; } // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. - if ($callback($results) === false) { + if (false === $callback($results)) { return false; } @@ -1960,8 +1923,8 @@ class Builder /** * Get an array with the values of a given column. * - * @param string $column - * @param string|null $key + * @param string $column + * @param string|null $key * @return \Hyperf\Utils\Collection */ public function pluck($column, $key = null) @@ -2012,9 +1975,9 @@ class Builder // boolean true. If there is no results for this query we will return false as // there are no rows for this query at all and we can return that info here. if (isset($results[0])) { - $results = (array)$results[0]; + $results = (array) $results[0]; - return (bool)$results['exists']; + return (bool) $results['exists']; } return false; @@ -2038,14 +2001,13 @@ class Builder */ public function count($columns = '*') { - return (int)$this->aggregate(__FUNCTION__, Arr::wrap($columns)); + return (int) $this->aggregate(__FUNCTION__, Arr::wrap($columns)); } /** * Retrieve the minimum value of a given column. * - * @param string $column - * @return mixed + * @param string $column */ public function min($column) { @@ -2055,8 +2017,7 @@ class Builder /** * Retrieve the maximum value of a given column. * - * @param string $column - * @return mixed + * @param string $column */ public function max($column) { @@ -2066,21 +2027,19 @@ class Builder /** * Retrieve the sum of the values of a given column. * - * @param string $column - * @return mixed + * @param string $column */ public function sum($column) { $result = $this->aggregate(__FUNCTION__, [$column]); - return $result ? : 0; + return $result ?: 0; } /** * Retrieve the average of the values of a given column. * - * @param string $column - * @return mixed + * @param string $column */ public function avg($column) { @@ -2090,8 +2049,7 @@ class Builder /** * Alias for the "avg" method. * - * @param string $column - * @return mixed + * @param string $column */ public function average($column) { @@ -2101,9 +2059,8 @@ class Builder /** * Execute an aggregate function on the database. * - * @param string $function - * @param array $columns - * @return mixed + * @param string $function + * @param array $columns */ public function aggregate($function, $columns = ['*']) { @@ -2113,15 +2070,15 @@ class Builder ->get($columns); if (! $results->isEmpty()) { - return array_change_key_case((array)$results[0])['aggregate']; + return array_change_key_case((array) $results[0])['aggregate']; } } /** * Execute a numeric aggregate function on the database. * - * @param string $function - * @param array $columns + * @param string $function + * @param array $columns * @return float|int */ public function numericAggregate($function, $columns = ['*']) @@ -2142,13 +2099,12 @@ class Builder // If the result doesn't contain a decimal place, we will assume it is an int then // cast it to one. When it does we will cast it to a float since it needs to be // cast to the expected data type for the developers out of pure convenience. - return strpos((string)$result, '.') === false ? (int)$result : (float)$result; + return false === strpos((string) $result, '.') ? (int) $result : (float) $result; } /** * Insert a new record into the database. * - * @param array $values * @return bool */ public function insert(array $values) @@ -2184,7 +2140,6 @@ class Builder /** * Insert a new record and get the value of the primary key. * - * @param array $values * @param string|null $sequence * @return int */ @@ -2200,7 +2155,6 @@ class Builder /** * Insert new records into the table using a subquery. * - * @param array $columns * @param \Closure|\Hyperf\Database\Query\Builder|string $query * @return bool */ @@ -2214,7 +2168,6 @@ class Builder /** * Update a record in the database. * - * @param array $values * @return int */ public function update(array $values) @@ -2227,8 +2180,6 @@ class Builder /** * Insert or update a record matching the attributes, and fill it with values. * - * @param array $attributes - * @param array $values * @return bool */ public function updateOrInsert(array $attributes, array $values = []) @@ -2237,15 +2188,14 @@ class Builder return $this->insert(array_merge($attributes, $values)); } - return (bool)$this->take(1)->update($values); + return (bool) $this->take(1)->update($values); } /** * Increment a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ public function increment($column, $amount = 1, array $extra = []) @@ -2264,9 +2214,8 @@ class Builder /** * Decrement a column's value by a given amount. * - * @param string $column + * @param string $column * @param float|int $amount - * @param array $extra * @return int */ public function decrement($column, $amount = 1, array $extra = []) @@ -2285,7 +2234,6 @@ class Builder /** * Delete a record from the database. * - * @param mixed $id * @return int */ public function delete($id = null) @@ -2302,8 +2250,6 @@ class Builder /** * Run a truncate statement on the table. - * - * @return void */ public function truncate() { @@ -2325,7 +2271,6 @@ class Builder /** * Create a raw database expression. * - * @param mixed $value * @return \Hyperf\Database\Query\Expression */ public function raw($value) @@ -2356,8 +2301,7 @@ class Builder /** * Set the bindings on the query builder. * - * @param array $bindings - * @param string $type + * @param string $type * @return $this * @throws \InvalidArgumentException */ @@ -2375,8 +2319,7 @@ class Builder /** * Add a binding to the query. * - * @param mixed $value - * @param string $type + * @param string $type * @return $this * @throws \InvalidArgumentException */ @@ -2453,7 +2396,6 @@ class Builder /** * Clone the query without the given properties. * - * @param array $properties * @return static */ public function cloneWithout(array $properties) @@ -2468,7 +2410,6 @@ class Builder /** * Clone the query without the given bindings. * - * @param array $except * @return static */ public function cloneWithoutBindings(array $except) @@ -2515,7 +2456,6 @@ class Builder /** * Parse the subquery into SQL and bindings. * - * @param mixed $query * @return array */ protected function parseSub($query) @@ -2525,13 +2465,13 @@ class Builder } elseif (is_string($query)) { return [$query, []]; } - throw new InvalidArgumentException; + throw new InvalidArgumentException(); } /** * Add an array of where clauses to the query. * - * @param array $column + * @param array $column * @param string $boolean * @param string $method * @return $this @@ -2554,7 +2494,6 @@ class Builder * Prevents using Null values with invalid operators. * * @param string $operator - * @param mixed $value * @return bool */ protected function invalidOperatorAndValue($operator, $value) @@ -2577,9 +2516,8 @@ class Builder * Add a where in with a sub-select to the query. * * @param string $column - * @param \Closure $callback * @param string $boolean - * @param bool $not + * @param bool $not * @return $this */ protected function whereInSub($column, Closure $callback, $boolean, $not) @@ -2601,10 +2539,10 @@ class Builder /** * Add an external sub-select to the query. * - * @param string $column + * @param string $column * @param \Hyperf\Database\Query\Builder|static $query - * @param string $boolean - * @param bool $not + * @param string $boolean + * @param bool $not * @return $this */ protected function whereInExistingQuery($column, $query, $boolean, $not) @@ -2624,7 +2562,6 @@ class Builder * @param string $type * @param string $column * @param string $operator - * @param mixed $value * @param string $boolean * @return $this */ @@ -2644,7 +2581,6 @@ class Builder * * @param string $column * @param string $operator - * @param \Closure $callback * @param string $boolean * @return $this */ @@ -2667,11 +2603,10 @@ class Builder /** * Add a single dynamic where clause statement to the query. * - * @param string $segment - * @param string $connector - * @param array $parameters - * @param int $index - * @return void + * @param string $segment + * @param string $connector + * @param array $parameters + * @param int $index */ protected function addDynamic($segment, $connector, $parameters, $index) { @@ -2726,20 +2661,18 @@ class Builder /** * Remove the column aliases since they will break count queries. * - * @param array $columns * @return array */ protected function withoutSelectAliases(array $columns) { return array_map(function ($column) { - return is_string($column) && ($aliasPosition = stripos($column, ' as ')) !== false ? substr($column, 0, $aliasPosition) : $column; + return is_string($column) && false !== ($aliasPosition = stripos($column, ' as ')) ? substr($column, 0, $aliasPosition) : $column; }, $columns); } /** * Throw an exception if the query doesn't have an orderBy clause. * - * @return void * @throws \RuntimeException */ protected function enforceOrderBy() @@ -2752,7 +2685,7 @@ class Builder /** * Strip off the table name or alias from a column identifier. * - * @param string $column + * @param string $column * @return string|null */ protected function stripTableForPluck($column) @@ -2763,9 +2696,9 @@ class Builder /** * Retrieve column values from rows represented as objects. * - * @param array $queryResult - * @param string $column - * @param string $key + * @param array $queryResult + * @param string $column + * @param string $key * @return \Hyperf\Utils\Collection */ protected function pluckFromObjectColumn($queryResult, $column, $key) @@ -2788,9 +2721,9 @@ class Builder /** * Retrieve column values from rows represented as arrays. * - * @param array $queryResult - * @param string $column - * @param string $key + * @param array $queryResult + * @param string $column + * @param string $key * @return \Hyperf\Utils\Collection */ protected function pluckFromArrayColumn($queryResult, $column, $key) @@ -2814,7 +2747,7 @@ class Builder * Set the aggregate property without running the query. * * @param string $function - * @param array $columns + * @param array $columns * @return $this */ protected function setAggregate($function, $columns) @@ -2834,9 +2767,8 @@ class Builder * Execute the given callback while selecting the given columns. * After running the callback, the columns are reset to the original value. * - * @param array $columns - * @param callable $callback - * @return mixed + * @param array $columns + * @param callable $callback */ protected function onceWithColumns($columns, $callback) { @@ -2866,7 +2798,6 @@ class Builder /** * Remove all of the expressions from a list of bindings. * - * @param array $bindings * @return array */ protected function cleanBindings(array $bindings) diff --git a/src/database/src/Query/Expression.php b/src/database/src/Query/Expression.php index 49119b05b..21361e6af 100755 --- a/src/database/src/Query/Expression.php +++ b/src/database/src/Query/Expression.php @@ -1,4 +1,5 @@ wrapTable($query->from); - if (!is_array(reset($values))) { + if (! is_array(reset($values))) { $values = [$values]; } @@ -150,8 +146,7 @@ class Grammar extends BaseGrammar /** * Compile an insert and get ID statement into SQL. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $values + * @param array $values * @param string $sequence * @return string */ @@ -163,9 +158,6 @@ class Grammar extends BaseGrammar /** * Compile an insert statement using a subquery into SQL. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $columns - * @param string $sql * @return string */ public function compileInsertUsing(Builder $query, array $columns, string $sql) @@ -176,8 +168,7 @@ class Grammar extends BaseGrammar /** * Compile an update statement into SQL. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $values + * @param array $values * @return string */ public function compileUpdate(Builder $query, $values) @@ -211,8 +202,6 @@ class Grammar extends BaseGrammar /** * Prepare the bindings for an update statement. * - * @param array $bindings - * @param array $values * @return array */ public function prepareBindingsForUpdate(array $bindings, array $values) @@ -227,7 +216,6 @@ class Grammar extends BaseGrammar /** * Compile a delete statement into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @return string */ public function compileDelete(Builder $query) @@ -240,7 +228,6 @@ class Grammar extends BaseGrammar /** * Prepare the bindings for a delete statement. * - * @param array $bindings * @return array */ public function prepareBindingsForDelete(array $bindings) @@ -251,7 +238,6 @@ class Grammar extends BaseGrammar /** * Compile a truncate table statement into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @return array */ public function compileTruncate(Builder $query) @@ -295,7 +281,7 @@ class Grammar extends BaseGrammar * Wrap a value in keyword identifiers. * * @param \Hyperf\Database\Query\Expression|string $value - * @param bool $prefixAlias + * @param bool $prefixAlias * @return string */ public function wrap($value, $prefixAlias = false) @@ -307,7 +293,7 @@ class Grammar extends BaseGrammar // If the value being wrapped has a column alias we will need to separate out // the pieces so we can wrap each of the segments of the expression on its // own, and then join these both back together using the "as" connector. - if (stripos($value, ' as ') !== false) { + if (false !== stripos($value, ' as ')) { return $this->wrapAliasedValue($value, $prefixAlias); } @@ -334,7 +320,6 @@ class Grammar extends BaseGrammar /** * Compile the components necessary for a select clause. * - * @param \Hyperf\Database\Query\Builder $query * @return array */ protected function compileComponents(Builder $query) @@ -345,7 +330,7 @@ class Grammar extends BaseGrammar // To compile the query, we'll spin through each component of the query and // see if that component exists. If it does we'll just call the compiler // function for the component which is responsible for making the SQL. - if (isset($query->$component) && !is_null($query->$component)) { + if (isset($query->$component) && ! is_null($query->$component)) { $method = 'compile' . ucfirst($component); $sql[$component] = $this->$method($query, $query->$component); @@ -358,8 +343,7 @@ class Grammar extends BaseGrammar /** * Compile an aggregated select clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $aggregate + * @param array $aggregate * @return string */ protected function compileAggregate(Builder $query, $aggregate) @@ -369,7 +353,7 @@ class Grammar extends BaseGrammar // If the query has a "distinct" constraint and we're not asking for all columns // we need to prepend "distinct" onto the column name so that the query takes // it into account when it performs the aggregating operations on the data. - if ($query->distinct && $column !== '*') { + if ($query->distinct && '*' !== $column) { $column = 'distinct ' . $column; } @@ -379,8 +363,7 @@ class Grammar extends BaseGrammar /** * Compile the "select *" portion of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $columns + * @param array $columns * @return string|null */ protected function compileColumns(Builder $query, $columns) @@ -388,7 +371,7 @@ class Grammar extends BaseGrammar // If the query is actually performing an aggregating select, we will let that // compiler handle the building of the select clauses, as it will need some // more syntax that is best handled by that function to keep things neat. - if (!is_null($query->aggregate)) { + if (! is_null($query->aggregate)) { return; } @@ -400,7 +383,6 @@ class Grammar extends BaseGrammar /** * Compile the "from" portion of the query. * - * @param \Hyperf\Database\Query\Builder $query * @param string $table * @return string */ @@ -412,8 +394,7 @@ class Grammar extends BaseGrammar /** * Compile the "join" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $joins + * @param array $joins * @return string */ protected function compileJoins(Builder $query, $joins) @@ -432,7 +413,6 @@ class Grammar extends BaseGrammar /** * Compile the "where" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query * @return string */ protected function compileWheres(Builder $query) @@ -471,7 +451,7 @@ class Grammar extends BaseGrammar * Format the where clause statements into one string. * * @param \Hyperf\Database\Query\Builder $query - * @param array $sql + * @param array $sql * @return string */ protected function concatenateWhereClauses($query, $sql) @@ -484,8 +464,7 @@ class Grammar extends BaseGrammar /** * Compile a raw where clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereRaw(Builder $query, $where) @@ -496,8 +475,7 @@ class Grammar extends BaseGrammar /** * Compile a basic where clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereBasic(Builder $query, $where) @@ -510,13 +488,12 @@ class Grammar extends BaseGrammar /** * Compile a "where in" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereIn(Builder $query, $where) { - if (!empty($where['values'])) { + if (! empty($where['values'])) { return $this->wrap($where['column']) . ' in (' . $this->parameterize($where['values']) . ')'; } @@ -526,13 +503,12 @@ class Grammar extends BaseGrammar /** * Compile a "where not in" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNotIn(Builder $query, $where) { - if (!empty($where['values'])) { + if (! empty($where['values'])) { return $this->wrap($where['column']) . ' not in (' . $this->parameterize($where['values']) . ')'; } @@ -544,13 +520,12 @@ class Grammar extends BaseGrammar * * For safety, whereIntegerInRaw ensures this method is only used with integer values. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNotInRaw(Builder $query, $where) { - if (!empty($where['values'])) { + if (! empty($where['values'])) { return $this->wrap($where['column']) . ' not in (' . implode(', ', $where['values']) . ')'; } @@ -560,8 +535,7 @@ class Grammar extends BaseGrammar /** * Compile a where in sub-select clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereInSub(Builder $query, $where) @@ -572,8 +546,7 @@ class Grammar extends BaseGrammar /** * Compile a where not in sub-select clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNotInSub(Builder $query, $where) @@ -586,13 +559,12 @@ class Grammar extends BaseGrammar * * For safety, whereIntegerInRaw ensures this method is only used with integer values. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereInRaw(Builder $query, $where) { - if (!empty($where['values'])) { + if (! empty($where['values'])) { return $this->wrap($where['column']) . ' in (' . implode(', ', $where['values']) . ')'; } @@ -602,8 +574,7 @@ class Grammar extends BaseGrammar /** * Compile a "where null" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNull(Builder $query, $where) @@ -614,8 +585,7 @@ class Grammar extends BaseGrammar /** * Compile a "where not null" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNotNull(Builder $query, $where) @@ -626,8 +596,7 @@ class Grammar extends BaseGrammar /** * Compile a "between" where clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereBetween(Builder $query, $where) @@ -644,8 +613,7 @@ class Grammar extends BaseGrammar /** * Compile a "where date" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereDate(Builder $query, $where) @@ -656,8 +624,7 @@ class Grammar extends BaseGrammar /** * Compile a "where time" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereTime(Builder $query, $where) @@ -668,8 +635,7 @@ class Grammar extends BaseGrammar /** * Compile a "where day" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereDay(Builder $query, $where) @@ -680,8 +646,7 @@ class Grammar extends BaseGrammar /** * Compile a "where month" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereMonth(Builder $query, $where) @@ -692,8 +657,7 @@ class Grammar extends BaseGrammar /** * Compile a "where year" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereYear(Builder $query, $where) @@ -705,8 +669,7 @@ class Grammar extends BaseGrammar * Compile a date based where clause. * * @param string $type - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function dateBasedWhere($type, Builder $query, $where) @@ -719,8 +682,7 @@ class Grammar extends BaseGrammar /** * Compile a where clause comparing two columns.. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereColumn(Builder $query, $where) @@ -731,8 +693,7 @@ class Grammar extends BaseGrammar /** * Compile a nested where clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNested(Builder $query, $where) @@ -748,8 +709,7 @@ class Grammar extends BaseGrammar /** * Compile a where condition with a sub-select. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereSub(Builder $query, $where) @@ -762,8 +722,7 @@ class Grammar extends BaseGrammar /** * Compile a where exists clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereExists(Builder $query, $where) @@ -774,8 +733,7 @@ class Grammar extends BaseGrammar /** * Compile a where exists clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereNotExists(Builder $query, $where) @@ -786,8 +744,7 @@ class Grammar extends BaseGrammar /** * Compile a where row values condition. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereRowValues(Builder $query, $where) @@ -802,8 +759,7 @@ class Grammar extends BaseGrammar /** * Compile a "where JSON contains" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereJsonContains(Builder $query, $where) @@ -833,8 +789,7 @@ class Grammar extends BaseGrammar /** * Compile a "where JSON length" clause. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $where + * @param array $where * @return string */ protected function whereJsonLength(Builder $query, $where) @@ -864,8 +819,7 @@ class Grammar extends BaseGrammar /** * Compile the "group by" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $groups + * @param array $groups * @return string */ protected function compileGroups(Builder $query, $groups) @@ -876,8 +830,7 @@ class Grammar extends BaseGrammar /** * Compile the "having" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $havings + * @param array $havings * @return string */ protected function compileHavings(Builder $query, $havings) @@ -890,7 +843,6 @@ class Grammar extends BaseGrammar /** * Compile a single having clause. * - * @param array $having * @return string */ protected function compileHaving(array $having) @@ -898,9 +850,9 @@ class Grammar extends BaseGrammar // If the having clause is "raw", we can just return the clause straight away // without doing any more processing on it. Otherwise, we will compile the // clause into SQL based on the components that make it up from builder. - if ($having['type'] === 'Raw') { + if ('Raw' === $having['type']) { return $having['boolean'] . ' ' . $having['sql']; - } elseif ($having['type'] === 'between') { + } elseif ('between' === $having['type']) { return $this->compileHavingBetween($having); } @@ -910,7 +862,7 @@ class Grammar extends BaseGrammar /** * Compile a basic having clause. * - * @param array $having + * @param array $having * @return string */ protected function compileBasicHaving($having) @@ -925,7 +877,7 @@ class Grammar extends BaseGrammar /** * Compile a "between" having clause. * - * @param array $having + * @param array $having * @return string */ protected function compileHavingBetween($having) @@ -944,13 +896,12 @@ class Grammar extends BaseGrammar /** * Compile the "order by" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param array $orders + * @param array $orders * @return string */ protected function compileOrders(Builder $query, $orders) { - if (!empty($orders)) { + if (! empty($orders)) { return 'order by ' . implode(', ', $this->compileOrdersToArray($query, $orders)); } @@ -960,14 +911,13 @@ class Grammar extends BaseGrammar /** * Compile the query orders to an array. * - * @param \Hyperf\Database\Query\Builder $query * @param array $orders * @return array */ protected function compileOrdersToArray(Builder $query, $orders) { return array_map(function ($order) { - return !isset($order['sql']) + return ! isset($order['sql']) ? $this->wrap($order['column']) . ' ' . $order['direction'] : $order['sql']; }, $orders); @@ -976,31 +926,28 @@ class Grammar extends BaseGrammar /** * Compile the "limit" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param int $limit + * @param int $limit * @return string */ protected function compileLimit(Builder $query, $limit) { - return 'limit ' . (int)$limit; + return 'limit ' . (int) $limit; } /** * Compile the "offset" portions of the query. * - * @param \Hyperf\Database\Query\Builder $query - * @param int $offset + * @param int $offset * @return string */ protected function compileOffset(Builder $query, $offset) { - return 'offset ' . (int)$offset; + return 'offset ' . (int) $offset; } /** * Compile the "union" queries attached to the main query. * - * @param \Hyperf\Database\Query\Builder $query * @return string */ protected function compileUnions(Builder $query) @@ -1011,7 +958,7 @@ class Grammar extends BaseGrammar $sql .= $this->compileUnion($union); } - if (!empty($query->unionOrders)) { + if (! empty($query->unionOrders)) { $sql .= ' ' . $this->compileOrders($query, $query->unionOrders); } @@ -1029,7 +976,6 @@ class Grammar extends BaseGrammar /** * Compile a single union statement. * - * @param array $union * @return string */ protected function compileUnion(array $union) @@ -1042,7 +988,6 @@ class Grammar extends BaseGrammar /** * Compile a union aggregate query into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @return string */ protected function compileUnionAggregate(Builder $query) @@ -1057,7 +1002,6 @@ class Grammar extends BaseGrammar /** * Compile the lock into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @param bool|string $value * @return string */ @@ -1120,13 +1064,13 @@ class Grammar extends BaseGrammar /** * Concatenate an array of segments, removing empties. * - * @param array $segments + * @param array $segments * @return string */ protected function concatenate($segments) { return implode(' ', array_filter($segments, function ($value) { - return (string)$value !== ''; + return '' !== (string) $value; })); } diff --git a/src/database/src/Query/Grammars/MySqlGrammar.php b/src/database/src/Query/Grammars/MySqlGrammar.php index f2c0c504a..33511f79c 100755 --- a/src/database/src/Query/Grammars/MySqlGrammar.php +++ b/src/database/src/Query/Grammars/MySqlGrammar.php @@ -1,4 +1,5 @@ orders)) { + if (! empty($query->orders)) { $sql .= ' ' . $this->compileOrders($query, $query->orders); } @@ -129,8 +128,6 @@ class MySqlGrammar extends Grammar * * Booleans, integers, and doubles are inserted into JSON updates as raw values. * - * @param array $bindings - * @param array $values * @return array */ public function prepareBindingsForUpdate(array $bindings, array $values) @@ -145,7 +142,6 @@ class MySqlGrammar extends Grammar /** * Compile a delete statement into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @return string */ public function compileDelete(Builder $query) @@ -162,7 +158,6 @@ class MySqlGrammar extends Grammar /** * Prepare the bindings for a delete statement. * - * @param array $bindings * @return array */ public function prepareBindingsForDelete(array $bindings) @@ -206,7 +201,6 @@ class MySqlGrammar extends Grammar /** * Compile a single union statement. * - * @param array $union * @return string */ protected function compileUnion(array $union) @@ -219,13 +213,12 @@ class MySqlGrammar extends Grammar /** * Compile the lock into SQL. * - * @param \Hyperf\Database\Query\Builder $query * @param bool|string $value * @return string */ protected function compileLock(Builder $query, $value) { - if (!is_string($value)) { + if (! is_string($value)) { return $value ? 'for update' : 'lock in share mode'; } @@ -235,7 +228,7 @@ class MySqlGrammar extends Grammar /** * Compile all of the columns for an update statement. * - * @param array $values + * @param array $values * @return string */ protected function compileUpdateColumns($values) @@ -253,7 +246,6 @@ class MySqlGrammar extends Grammar * Prepares a JSON column being updated using the JSON_SET function. * * @param string $key - * @param \Hyperf\Database\Query\JsonExpression $value * @return string */ protected function compileJsonUpdateColumn($key, JsonExpression $value) @@ -267,8 +259,8 @@ class MySqlGrammar extends Grammar * Compile a delete query that does not use joins. * * @param \Hyperf\Database\Query\Builder $query - * @param string $table - * @param array $where + * @param string $table + * @param array $where * @return string */ protected function compileDeleteWithoutJoins($query, $table, $where) @@ -278,7 +270,7 @@ class MySqlGrammar extends Grammar // When using MySQL, delete statements may contain order by statements and limits // so we will compile both of those here. Once we have finished compiling this // we will return the completed SQL statement so it will be executed for us. - if (!empty($query->orders)) { + if (! empty($query->orders)) { $sql .= ' ' . $this->compileOrders($query, $query->orders); } @@ -293,15 +285,15 @@ class MySqlGrammar extends Grammar * Compile a delete query that uses joins. * * @param \Hyperf\Database\Query\Builder $query - * @param string $table - * @param array $where + * @param string $table + * @param array $where * @return string */ protected function compileDeleteWithJoins($query, $table, $where) { $joins = ' ' . $this->compileJoins($query, $query->joins); - $alias = stripos($table, ' as ') !== false + $alias = false !== stripos($table, ' as ') ? explode(' as ', $table)[1] : $table; return trim("delete {$alias} from {$table}{$joins} {$where}"); @@ -315,7 +307,7 @@ class MySqlGrammar extends Grammar */ protected function wrapValue($value) { - return $value === '*' ? $value : '`' . str_replace('`', '``', $value) . '`'; + return '*' === $value ? $value : '`' . str_replace('`', '``', $value) . '`'; } /** diff --git a/src/database/src/Query/JoinClause.php b/src/database/src/Query/JoinClause.php index 0663a6ade..5057e60f7 100755 --- a/src/database/src/Query/JoinClause.php +++ b/src/database/src/Query/JoinClause.php @@ -1,4 +1,5 @@ getConnection()->getPdo()->lastInsertId($sequence); - return is_numeric($id) ? (int)$id : $id; + return is_numeric($id) ? (int) $id : $id; } /** diff --git a/src/database/src/Schema/Blueprint.php b/src/database/src/Schema/Blueprint.php index 00b307fcd..53dd4c6a7 100755 --- a/src/database/src/Schema/Blueprint.php +++ b/src/database/src/Schema/Blueprint.php @@ -1,4 +1,5 @@ table = $table; $this->prefix = $prefix; - if (!is_null($callback)) { + if (! is_null($callback)) { $callback($this); } } /** * Execute the blueprint against the database. - * - * @param \Hyperf\Database\Connection $connection - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar - * @return void */ public function build(Connection $connection, Grammar $grammar) { @@ -110,8 +105,6 @@ class Blueprint /** * Get the raw SQL statements for the blueprint. * - * @param \Hyperf\Database\Connection $connection - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar * @return array */ public function toSql(Connection $connection, Grammar $grammar) @@ -129,8 +122,8 @@ class Blueprint $method = 'compile' . ucfirst($command->name); if (method_exists($grammar, $method)) { - if (!is_null($sql = $grammar->$method($this, $command, $connection))) { - $statements = array_merge($statements, (array)$sql); + if (! is_null($sql = $grammar->$method($this, $command, $connection))) { + $statements = array_merge($statements, (array) $sql); } } } @@ -140,9 +133,6 @@ class Blueprint /** * Add the fluent commands specified on any columns. - * - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar - * @return void */ public function addFluentCommands(Grammar $grammar) { @@ -150,7 +140,7 @@ class Blueprint foreach ($grammar->getFluentCommands() as $commandName) { $attributeName = lcfirst($commandName); - if (!isset($column->{$attributeName})) { + if (! isset($column->{$attributeName})) { continue; } @@ -176,8 +166,6 @@ class Blueprint /** * Indicate that the table needs to be temporary. - * - * @return void */ public function temporary() { @@ -207,7 +195,7 @@ class Blueprint /** * Indicate that the given columns should be dropped. * - * @param array|mixed $columns + * @param array|mixed $columns * @return \Hyperf\Utils\Fluent */ public function dropColumn($columns) @@ -220,8 +208,8 @@ class Blueprint /** * Indicate that the given columns should be renamed. * - * @param string $from - * @param string $to + * @param string $from + * @param string $to * @return \Hyperf\Utils\Fluent */ public function renameColumn($from, $to) @@ -232,7 +220,7 @@ class Blueprint /** * Indicate that the given primary key should be dropped. * - * @param string|array $index + * @param string|array $index * @return \Hyperf\Utils\Fluent */ public function dropPrimary($index = null) @@ -243,7 +231,7 @@ class Blueprint /** * Indicate that the given unique key should be dropped. * - * @param string|array $index + * @param string|array $index * @return \Hyperf\Utils\Fluent */ public function dropUnique($index) @@ -254,7 +242,7 @@ class Blueprint /** * Indicate that the given index should be dropped. * - * @param string|array $index + * @param string|array $index * @return \Hyperf\Utils\Fluent */ public function dropIndex($index) @@ -265,7 +253,7 @@ class Blueprint /** * Indicate that the given spatial index should be dropped. * - * @param string|array $index + * @param string|array $index * @return \Hyperf\Utils\Fluent */ public function dropSpatialIndex($index) @@ -276,7 +264,7 @@ class Blueprint /** * Indicate that the given foreign key should be dropped. * - * @param string|array $index + * @param string|array $index * @return \Hyperf\Utils\Fluent */ public function dropForeign($index) @@ -287,8 +275,8 @@ class Blueprint /** * Indicate that the given indexes should be renamed. * - * @param string $from - * @param string $to + * @param string $from + * @param string $to * @return \Hyperf\Utils\Fluent */ public function renameIndex($from, $to) @@ -298,8 +286,6 @@ class Blueprint /** * Indicate that the timestamp columns should be dropped. - * - * @return void */ public function dropTimestamps() { @@ -308,8 +294,6 @@ class Blueprint /** * Indicate that the timestamp columns should be dropped. - * - * @return void */ public function dropTimestampsTz() { @@ -319,8 +303,7 @@ class Blueprint /** * Indicate that the soft delete column should be dropped. * - * @param string $column - * @return void + * @param string $column */ public function dropSoftDeletes($column = 'deleted_at') { @@ -330,8 +313,7 @@ class Blueprint /** * Indicate that the soft delete column should be dropped. * - * @param string $column - * @return void + * @param string $column */ public function dropSoftDeletesTz($column = 'deleted_at') { @@ -340,8 +322,6 @@ class Blueprint /** * Indicate that the remember token column should be dropped. - * - * @return void */ public function dropRememberToken() { @@ -351,9 +331,8 @@ class Blueprint /** * Indicate that the polymorphic columns should be dropped. * - * @param string $name - * @param string|null $indexName - * @return void + * @param string $name + * @param string|null $indexName */ public function dropMorphs($name, $indexName = null) { @@ -365,7 +344,7 @@ class Blueprint /** * Rename the table to a given name. * - * @param string $to + * @param string $to * @return \Hyperf\Utils\Fluent */ public function rename($to) @@ -376,9 +355,9 @@ class Blueprint /** * Specify the primary key(s) for the table. * - * @param string|array $columns - * @param string $name - * @param string|null $algorithm + * @param string|array $columns + * @param string $name + * @param string|null $algorithm * @return \Hyperf\Utils\Fluent */ public function primary($columns, $name = null, $algorithm = null) @@ -389,9 +368,9 @@ class Blueprint /** * Specify a unique index for the table. * - * @param string|array $columns - * @param string $name - * @param string|null $algorithm + * @param string|array $columns + * @param string $name + * @param string|null $algorithm * @return \Hyperf\Utils\Fluent */ public function unique($columns, $name = null, $algorithm = null) @@ -402,9 +381,9 @@ class Blueprint /** * Specify an index for the table. * - * @param string|array $columns - * @param string $name - * @param string|null $algorithm + * @param string|array $columns + * @param string $name + * @param string|null $algorithm * @return \Hyperf\Utils\Fluent */ public function index($columns, $name = null, $algorithm = null) @@ -415,8 +394,8 @@ class Blueprint /** * Specify a spatial index for the table. * - * @param string|array $columns - * @param string $name + * @param string|array $columns + * @param string $name * @return \Hyperf\Utils\Fluent */ public function spatialIndex($columns, $name = null) @@ -427,8 +406,8 @@ class Blueprint /** * Specify a foreign key for the table. * - * @param string|array $columns - * @param string $name + * @param string|array $columns + * @param string $name * @return \Hyperf\Utils\Fluent */ public function foreign($columns, $name = null) @@ -439,7 +418,7 @@ class Blueprint /** * Create a new auto-incrementing integer (4-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function increments($column) @@ -450,7 +429,7 @@ class Blueprint /** * Create a new auto-incrementing integer (4-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function integerIncrements($column) @@ -461,7 +440,7 @@ class Blueprint /** * Create a new auto-incrementing tiny integer (1-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function tinyIncrements($column) @@ -472,7 +451,7 @@ class Blueprint /** * Create a new auto-incrementing small integer (2-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function smallIncrements($column) @@ -483,7 +462,7 @@ class Blueprint /** * Create a new auto-incrementing medium integer (3-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function mediumIncrements($column) @@ -494,7 +473,7 @@ class Blueprint /** * Create a new auto-incrementing big integer (8-byte) column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function bigIncrements($column) @@ -505,8 +484,8 @@ class Blueprint /** * Create a new char column on the table. * - * @param string $column - * @param int $length + * @param string $column + * @param int $length * @return \Hyperf\Database\Schema\ColumnDefinition */ public function char($column, $length = null) @@ -519,8 +498,8 @@ class Blueprint /** * Create a new string column on the table. * - * @param string $column - * @param int $length + * @param string $column + * @param int $length * @return \Hyperf\Database\Schema\ColumnDefinition */ public function string($column, $length = null) @@ -533,7 +512,7 @@ class Blueprint /** * Create a new text column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function text($column) @@ -544,7 +523,7 @@ class Blueprint /** * Create a new medium text column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function mediumText($column) @@ -555,7 +534,7 @@ class Blueprint /** * Create a new long text column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function longText($column) @@ -566,9 +545,9 @@ class Blueprint /** * Create a new integer (4-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement - * @param bool $unsigned + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned * @return \Hyperf\Database\Schema\ColumnDefinition */ public function integer($column, $autoIncrement = false, $unsigned = false) @@ -579,9 +558,9 @@ class Blueprint /** * Create a new tiny integer (1-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement - * @param bool $unsigned + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned * @return \Hyperf\Database\Schema\ColumnDefinition */ public function tinyInteger($column, $autoIncrement = false, $unsigned = false) @@ -592,9 +571,9 @@ class Blueprint /** * Create a new small integer (2-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement - * @param bool $unsigned + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned * @return \Hyperf\Database\Schema\ColumnDefinition */ public function smallInteger($column, $autoIncrement = false, $unsigned = false) @@ -605,9 +584,9 @@ class Blueprint /** * Create a new medium integer (3-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement - * @param bool $unsigned + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned * @return \Hyperf\Database\Schema\ColumnDefinition */ public function mediumInteger($column, $autoIncrement = false, $unsigned = false) @@ -618,9 +597,9 @@ class Blueprint /** * Create a new big integer (8-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement - * @param bool $unsigned + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned * @return \Hyperf\Database\Schema\ColumnDefinition */ public function bigInteger($column, $autoIncrement = false, $unsigned = false) @@ -631,8 +610,8 @@ class Blueprint /** * Create a new unsigned integer (4-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement + * @param string $column + * @param bool $autoIncrement * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedInteger($column, $autoIncrement = false) @@ -643,8 +622,8 @@ class Blueprint /** * Create a new unsigned tiny integer (1-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement + * @param string $column + * @param bool $autoIncrement * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedTinyInteger($column, $autoIncrement = false) @@ -655,8 +634,8 @@ class Blueprint /** * Create a new unsigned small integer (2-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement + * @param string $column + * @param bool $autoIncrement * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedSmallInteger($column, $autoIncrement = false) @@ -667,8 +646,8 @@ class Blueprint /** * Create a new unsigned medium integer (3-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement + * @param string $column + * @param bool $autoIncrement * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedMediumInteger($column, $autoIncrement = false) @@ -679,8 +658,8 @@ class Blueprint /** * Create a new unsigned big integer (8-byte) column on the table. * - * @param string $column - * @param bool $autoIncrement + * @param string $column + * @param bool $autoIncrement * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedBigInteger($column, $autoIncrement = false) @@ -691,9 +670,9 @@ class Blueprint /** * Create a new float column on the table. * - * @param string $column - * @param int $total - * @param int $places + * @param string $column + * @param int $total + * @param int $places * @return \Hyperf\Database\Schema\ColumnDefinition */ public function float($column, $total = 8, $places = 2) @@ -704,9 +683,9 @@ class Blueprint /** * Create a new double column on the table. * - * @param string $column - * @param int|null $total - * @param int|null $places + * @param string $column + * @param int|null $total + * @param int|null $places * @return \Hyperf\Database\Schema\ColumnDefinition */ public function double($column, $total = null, $places = null) @@ -717,9 +696,9 @@ class Blueprint /** * Create a new decimal column on the table. * - * @param string $column - * @param int $total - * @param int $places + * @param string $column + * @param int $total + * @param int $places * @return \Hyperf\Database\Schema\ColumnDefinition */ public function decimal($column, $total = 8, $places = 2) @@ -730,9 +709,9 @@ class Blueprint /** * Create a new unsigned decimal column on the table. * - * @param string $column - * @param int $total - * @param int $places + * @param string $column + * @param int $total + * @param int $places * @return \Hyperf\Database\Schema\ColumnDefinition */ public function unsignedDecimal($column, $total = 8, $places = 2) @@ -745,7 +724,7 @@ class Blueprint /** * Create a new boolean column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function boolean($column) @@ -756,8 +735,7 @@ class Blueprint /** * Create a new enum column on the table. * - * @param string $column - * @param array $allowed + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function enum($column, array $allowed) @@ -768,7 +746,7 @@ class Blueprint /** * Create a new json column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function json($column) @@ -779,7 +757,7 @@ class Blueprint /** * Create a new jsonb column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function jsonb($column) @@ -790,7 +768,7 @@ class Blueprint /** * Create a new date column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function date($column) @@ -801,8 +779,8 @@ class Blueprint /** * Create a new date-time column on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function dateTime($column, $precision = 0) @@ -813,8 +791,8 @@ class Blueprint /** * Create a new date-time column (with time zone) on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function dateTimeTz($column, $precision = 0) @@ -825,8 +803,8 @@ class Blueprint /** * Create a new time column on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function time($column, $precision = 0) @@ -837,8 +815,8 @@ class Blueprint /** * Create a new time column (with time zone) on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function timeTz($column, $precision = 0) @@ -849,8 +827,8 @@ class Blueprint /** * Create a new timestamp column on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function timestamp($column, $precision = 0) @@ -861,8 +839,8 @@ class Blueprint /** * Create a new timestamp (with time zone) column on the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function timestampTz($column, $precision = 0) @@ -873,8 +851,7 @@ class Blueprint /** * Add nullable creation and update timestamps to the table. * - * @param int $precision - * @return void + * @param int $precision */ public function timestamps($precision = 0) { @@ -888,8 +865,7 @@ class Blueprint * * Alias for self::timestamps(). * - * @param int $precision - * @return void + * @param int $precision */ public function nullableTimestamps($precision = 0) { @@ -899,8 +875,7 @@ class Blueprint /** * Add creation and update timestampTz columns to the table. * - * @param int $precision - * @return void + * @param int $precision */ public function timestampsTz($precision = 0) { @@ -912,8 +887,8 @@ class Blueprint /** * Add a "deleted at" timestamp for the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function softDeletes($column = 'deleted_at', $precision = 0) @@ -924,8 +899,8 @@ class Blueprint /** * Add a "deleted at" timestampTz for the table. * - * @param string $column - * @param int $precision + * @param string $column + * @param int $precision * @return \Hyperf\Database\Schema\ColumnDefinition */ public function softDeletesTz($column = 'deleted_at', $precision = 0) @@ -936,7 +911,7 @@ class Blueprint /** * Create a new year column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function year($column) @@ -947,7 +922,7 @@ class Blueprint /** * Create a new binary column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function binary($column) @@ -958,7 +933,7 @@ class Blueprint /** * Create a new uuid column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function uuid($column) @@ -969,7 +944,7 @@ class Blueprint /** * Create a new IP address column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function ipAddress($column) @@ -980,7 +955,7 @@ class Blueprint /** * Create a new MAC address column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function macAddress($column) @@ -991,7 +966,7 @@ class Blueprint /** * Create a new geometry column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function geometry($column) @@ -1002,8 +977,8 @@ class Blueprint /** * Create a new point column on the table. * - * @param string $column - * @param int|null $srid + * @param string $column + * @param int|null $srid * @return \Hyperf\Database\Schema\ColumnDefinition */ public function point($column, $srid = null) @@ -1014,7 +989,7 @@ class Blueprint /** * Create a new linestring column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function lineString($column) @@ -1025,7 +1000,7 @@ class Blueprint /** * Create a new polygon column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function polygon($column) @@ -1036,7 +1011,7 @@ class Blueprint /** * Create a new geometrycollection column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function geometryCollection($column) @@ -1047,7 +1022,7 @@ class Blueprint /** * Create a new multipoint column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function multiPoint($column) @@ -1058,7 +1033,7 @@ class Blueprint /** * Create a new multilinestring column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function multiLineString($column) @@ -1069,7 +1044,7 @@ class Blueprint /** * Create a new multipolygon column on the table. * - * @param string $column + * @param string $column * @return \Hyperf\Database\Schema\ColumnDefinition */ public function multiPolygon($column) @@ -1080,9 +1055,8 @@ class Blueprint /** * Add the proper columns for a polymorphic table. * - * @param string $name - * @param string|null $indexName - * @return void + * @param string $name + * @param string|null $indexName */ public function morphs($name, $indexName = null) { @@ -1096,9 +1070,8 @@ class Blueprint /** * Add nullable columns for a polymorphic table. * - * @param string $name - * @param string|null $indexName - * @return void + * @param string $name + * @param string|null $indexName */ public function nullableMorphs($name, $indexName = null) { @@ -1122,9 +1095,8 @@ class Blueprint /** * Add a new column to the blueprint. * - * @param string $type - * @param string $name - * @param array $parameters + * @param string $type + * @param string $name * @return \Hyperf\Database\Schema\ColumnDefinition */ public function addColumn($type, $name, array $parameters = []) @@ -1189,7 +1161,7 @@ class Blueprint public function getAddedColumns() { return array_filter($this->columns, function ($column) { - return !$column->change; + return ! $column->change; }); } @@ -1201,15 +1173,13 @@ class Blueprint public function getChangedColumns() { return array_filter($this->columns, function ($column) { - return (bool)$column->change; + return (bool) $column->change; }); } /** * Ensure the commands on the blueprint are valid for the connection type. * - * @param \Hyperf\Database\Connection $connection - * @return void * * @throws \BadMethodCallException */ @@ -1233,7 +1203,6 @@ class Blueprint /** * Get all of the commands matching the given names. * - * @param array $names * @return \Hyperf\Utils\Collection */ protected function commandsNamed(array $names) @@ -1245,17 +1214,14 @@ class Blueprint /** * Add the commands that are implied by the blueprint's state. - * - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar - * @return void */ protected function addImpliedCommands(Grammar $grammar) { - if (count($this->getAddedColumns()) > 0 && !$this->creating()) { + if (count($this->getAddedColumns()) > 0 && ! $this->creating()) { array_unshift($this->commands, $this->createCommand('add')); } - if (count($this->getChangedColumns()) > 0 && !$this->creating()) { + if (count($this->getChangedColumns()) > 0 && ! $this->creating()) { array_unshift($this->commands, $this->createCommand('change')); } @@ -1266,8 +1232,6 @@ class Blueprint /** * Add the index commands fluently specified on columns. - * - * @return void */ protected function addFluentIndexes() { @@ -1276,7 +1240,7 @@ class Blueprint // If the index has been specified on the given column, but is simply equal // to "true" (boolean), no name has been specified for this index so the // index method can be called without a name and it will generate one. - if ($column->{$index} === true) { + if (true === $column->{$index}) { $this->{$index}($column->name); continue 2; @@ -1302,22 +1266,22 @@ class Blueprint protected function creating() { return collect($this->commands)->contains(function ($command) { - return $command->name === 'create'; + return 'create' === $command->name; }); } /** * Add a new index command to the blueprint. * - * @param string $type - * @param string|array $columns - * @param string $index - * @param string|null $algorithm + * @param string $type + * @param string|array $columns + * @param string $index + * @param string|null $algorithm * @return \Hyperf\Utils\Fluent */ protected function indexCommand($type, $columns, $index, $algorithm = null) { - $columns = (array)$columns; + $columns = (array) $columns; // If no name was specified for this index, we will create one using a basic // convention of the table name, followed by the columns, followed by an @@ -1333,9 +1297,9 @@ class Blueprint /** * Create a new drop index command on the blueprint. * - * @param string $command - * @param string $type - * @param string|array $index + * @param string $command + * @param string $type + * @param string|array $index * @return \Hyperf\Utils\Fluent */ protected function dropIndexCommand($command, $type, $index) @@ -1356,7 +1320,6 @@ class Blueprint * Create a default index name for the table. * * @param string $type - * @param array $columns * @return string */ protected function createIndexName($type, array $columns) @@ -1369,8 +1332,7 @@ class Blueprint /** * Add a new command to the blueprint. * - * @param string $name - * @param array $parameters + * @param string $name * @return \Hyperf\Utils\Fluent */ protected function addCommand($name, array $parameters = []) @@ -1383,8 +1345,7 @@ class Blueprint /** * Create a new Fluent command. * - * @param string $name - * @param array $parameters + * @param string $name * @return \Hyperf\Utils\Fluent */ protected function createCommand($name, array $parameters = []) diff --git a/src/database/src/Schema/Builder.php b/src/database/src/Schema/Builder.php index 5d9a1ecf4..ad19d905a 100755 --- a/src/database/src/Schema/Builder.php +++ b/src/database/src/Schema/Builder.php @@ -1,4 +1,5 @@ connection = $connection; $this->grammar = $connection->getSchemaGrammar(); @@ -60,8 +61,7 @@ class Builder /** * Set the default string length for migrations. * - * @param int $length - * @return void + * @param int $length */ public static function defaultStringLength($length) { @@ -103,7 +103,6 @@ class Builder * Determine if the given table has given columns. * * @param string $table - * @param array $columns * @return bool */ public function hasColumns($table, array $columns) @@ -111,7 +110,7 @@ class Builder $tableColumns = array_map('strtolower', $this->getColumnListing($table)); foreach ($columns as $column) { - if (!in_array(strtolower($column), $tableColumns)) { + if (! in_array(strtolower($column), $tableColumns)) { return false; } } @@ -151,9 +150,7 @@ class Builder /** * Modify a table on the schema. * - * @param string $table - * @param \Closure $callback - * @return void + * @param string $table */ public function table($table, Closure $callback) { @@ -163,9 +160,7 @@ class Builder /** * Create a new table on the schema. * - * @param string $table - * @param \Closure $callback - * @return void + * @param string $table */ public function create($table, Closure $callback) { @@ -179,8 +174,7 @@ class Builder /** * Drop a table from the schema. * - * @param string $table - * @return void + * @param string $table */ public function drop($table) { @@ -192,8 +186,7 @@ class Builder /** * Drop a table from the schema if it exists. * - * @param string $table - * @return void + * @param string $table */ public function dropIfExists($table) { @@ -205,7 +198,6 @@ class Builder /** * Drop all tables from the database. * - * @return void * * @throws \LogicException */ @@ -217,7 +209,6 @@ class Builder /** * Drop all views from the database. * - * @return void * * @throws \LogicException */ @@ -229,9 +220,8 @@ class Builder /** * Rename a table on the schema. * - * @param string $from - * @param string $to - * @return void + * @param string $from + * @param string $to */ public function rename($from, $to) { @@ -277,7 +267,6 @@ class Builder /** * Set the database connection instance. * - * @param \Hyperf\Database\Connection $connection * @return $this */ public function setConnection(Connection $connection) @@ -289,9 +278,6 @@ class Builder /** * Set the Schema Blueprint resolver callback. - * - * @param \Closure $resolver - * @return void */ public function blueprintResolver(Closure $resolver) { @@ -301,8 +287,7 @@ class Builder /** * Execute the blueprint to build / modify the table. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @return void + * @param \Hyperf\Database\Schema\Blueprint $blueprint */ protected function build(Blueprint $blueprint) { @@ -312,8 +297,7 @@ class Builder /** * Create a new command set with a Closure. * - * @param string $table - * @param \Closure|null $callback + * @param string $table * @return \Hyperf\Database\Schema\Blueprint */ protected function createBlueprint($table, Closure $callback = null) diff --git a/src/database/src/Schema/ColumnDefinition.php b/src/database/src/Schema/ColumnDefinition.php index 7c1a7cb95..db5dea307 100644 --- a/src/database/src/Schema/ColumnDefinition.php +++ b/src/database/src/Schema/ColumnDefinition.php @@ -1,4 +1,5 @@ getDoctrineSchemaManager() ); - if ($tableDiff !== false) { + if (false !== $tableDiff) { return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); } @@ -58,16 +56,14 @@ class ChangeColumn /** * Get the Doctrine table difference for the given changes. * - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar * @return \Doctrine\DBAL\Schema\TableDiff|bool */ protected static function getChangedDiff($grammar, Blueprint $blueprint, SchemaManager $schema) { - $current = $schema->listTableDetails($grammar->getTablePrefix().$blueprint->getTable()); + $current = $schema->listTableDetails($grammar->getTablePrefix() . $blueprint->getTable()); - return (new Comparator)->diffTable( + return (new Comparator())->diffTable( $current, static::getTableWithColumnChanges($blueprint, $current) ); @@ -76,8 +72,6 @@ class ChangeColumn /** * Get a copy of the given Doctrine table after making the column changes. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Doctrine\DBAL\Schema\Table $table * @return \Doctrine\DBAL\Schema\Table */ protected static function getTableWithColumnChanges(Blueprint $blueprint, Table $table) @@ -92,7 +86,7 @@ class ChangeColumn // use some different terminology for various column attributes on the tables. foreach ($fluent->getAttributes() as $key => $value) { if (! is_null($option = static::mapFluentOptionToDoctrine($key))) { - if (method_exists($column, $method = 'set'.ucfirst($option))) { + if (method_exists($column, $method = 'set' . ucfirst($option))) { $column->{$method}(static::mapFluentValueToDoctrine($option, $value)); } } @@ -105,8 +99,6 @@ class ChangeColumn /** * Get the Doctrine column instance for a column change. * - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Hyperf\Utils\Fluent $fluent * @return \Doctrine\DBAL\Schema\Column */ protected static function getDoctrineColumn(Table $table, Fluent $fluent) @@ -120,7 +112,6 @@ class ChangeColumn /** * Get the Doctrine column change options. * - * @param \Hyperf\Utils\Fluent $fluent * @return array */ protected static function getDoctrineColumnChangeOptions(Fluent $fluent) @@ -131,7 +122,7 @@ class ChangeColumn $options['length'] = static::calculateDoctrineTextLength($fluent['type']); } - if ($fluent['type'] === 'json') { + if ('json' === $fluent['type']) { $options['customSchemaOptions'] = [ 'collation' => '', ]; @@ -143,7 +134,7 @@ class ChangeColumn /** * Get the doctrine column type. * - * @param string $type + * @param string $type * @return \Doctrine\DBAL\Types\Type */ protected static function getDoctrineColumnType($type) @@ -172,7 +163,7 @@ class ChangeColumn /** * Calculate the proper column length to force the Doctrine text type. * - * @param string $type + * @param string $type * @return int */ protected static function calculateDoctrineTextLength($type) @@ -190,7 +181,7 @@ class ChangeColumn /** * Get the matching Doctrine option for a given Fluent attribute name. * - * @param string $attribute + * @param string $attribute * @return string|null */ protected static function mapFluentOptionToDoctrine($attribute) @@ -213,12 +204,10 @@ class ChangeColumn /** * Get the matching Doctrine value for a given Fluent attribute. * - * @param string $option - * @param mixed $value - * @return mixed + * @param string $option */ protected static function mapFluentValueToDoctrine($option, $value) { - return $option === 'notnull' ? ! $value : $value; + return 'notnull' === $option ? ! $value : $value; } } diff --git a/src/database/src/Schema/Grammars/Grammar.php b/src/database/src/Schema/Grammars/Grammar.php index 0bb3f1f33..fa90e3c2e 100755 --- a/src/database/src/Schema/Grammars/Grammar.php +++ b/src/database/src/Schema/Grammars/Grammar.php @@ -1,4 +1,5 @@ columnize($command->columns), $this->wrapTable($command->on), - $this->columnize((array)$command->references) + $this->columnize((array) $command->references) ); // Once we have the basic foreign key creation statement constructed we can // build out the syntax for what should happen on an update or delete of // the affected columns, which will get something like "cascade", etc. - if (!is_null($command->onDelete)) { + if (! is_null($command->onDelete)) { $sql .= " on delete {$command->onDelete}"; } - if (!is_null($command->onUpdate)) { + if (! is_null($command->onUpdate)) { $sql .= " on update {$command->onUpdate}"; } @@ -109,7 +102,6 @@ abstract class Grammar extends BaseGrammar * Add a prefix to an array of values. * * @param string $prefix - * @param array $values * @return array */ public function prefixArray($prefix, array $values) @@ -122,7 +114,6 @@ abstract class Grammar extends BaseGrammar /** * Wrap a table in keyword identifiers. * - * @param mixed $table * @return string */ public function wrapTable($table) @@ -136,7 +127,7 @@ abstract class Grammar extends BaseGrammar * Wrap a value in keyword identifiers. * * @param \Hyperf\Database\Query\Expression|string $value - * @param bool $prefixAlias + * @param bool $prefixAlias * @return string */ public function wrap($value, $prefixAlias = false) @@ -150,8 +141,6 @@ abstract class Grammar extends BaseGrammar /** * Create an empty Doctrine DBAL TableDiff from the Blueprint. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema * @return \Doctrine\DBAL\Schema\TableDiff */ public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema) @@ -186,7 +175,6 @@ abstract class Grammar extends BaseGrammar /** * Compile the blueprint's column definitions. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint * @return array */ protected function getColumns(Blueprint $blueprint) @@ -208,7 +196,6 @@ abstract class Grammar extends BaseGrammar /** * Get the SQL for the column data type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function getType(Fluent $column) @@ -220,8 +207,6 @@ abstract class Grammar extends BaseGrammar * Add the column modifiers to the definition. * * @param string $sql - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function addModifiers($sql, Blueprint $blueprint, Fluent $column) @@ -238,8 +223,7 @@ abstract class Grammar extends BaseGrammar /** * Get the primary key command if it exists on the blueprint. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param string $name + * @param string $name * @return \Hyperf\Utils\Fluent|null */ protected function getCommandByName(Blueprint $blueprint, $name) @@ -254,7 +238,6 @@ abstract class Grammar extends BaseGrammar /** * Get all of the commands with a given name. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint * @param string $name * @return array */ @@ -268,7 +251,6 @@ abstract class Grammar extends BaseGrammar /** * Format a value so that it can be used in "default" clauses. * - * @param mixed $value * @return string */ protected function getDefaultValue($value) @@ -278,7 +260,7 @@ abstract class Grammar extends BaseGrammar } return is_bool($value) - ? "'" . (int)$value . "'" - : "'" . (string)$value . "'"; + ? "'" . (int) $value . "'" + : "'" . (string) $value . "'"; } } diff --git a/src/database/src/Schema/Grammars/MySqlGrammar.php b/src/database/src/Schema/Grammars/MySqlGrammar.php index 7cbaf6416..4424b8f0b 100755 --- a/src/database/src/Schema/Grammars/MySqlGrammar.php +++ b/src/database/src/Schema/Grammars/MySqlGrammar.php @@ -1,4 +1,5 @@ charset)) { $sql .= ' default character set ' . $blueprint->charset; - } elseif (!is_null($charset = $connection->getConfig('charset'))) { + } elseif (! is_null($charset = $connection->getConfig('charset'))) { $sql .= ' default character set ' . $charset; } @@ -480,7 +438,7 @@ class MySqlGrammar extends Grammar // connection that the query is targeting. We'll add it to this SQL query. if (isset($blueprint->collation)) { $sql .= " collate '{$blueprint->collation}'"; - } elseif (!is_null($collation = $connection->getConfig('collation'))) { + } elseif (! is_null($collation = $connection->getConfig('collation'))) { $sql .= " collate '{$collation}'"; } @@ -491,15 +449,13 @@ class MySqlGrammar extends Grammar * Append the engine specifications to a command. * * @param string $sql - * @param \Hyperf\Database\Connection $connection - * @param \Hyperf\Database\Schema\Blueprint $blueprint * @return string */ protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint) { if (isset($blueprint->engine)) { return $sql . ' engine = ' . $blueprint->engine; - } elseif (!is_null($engine = $connection->getConfig('engine'))) { + } elseif (! is_null($engine = $connection->getConfig('engine'))) { return $sql . ' engine = ' . $engine; } @@ -509,8 +465,6 @@ class MySqlGrammar extends Grammar /** * Compile an index creation command. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $command * @param string $type * @return string */ @@ -529,7 +483,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a char type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeChar(Fluent $column) @@ -540,7 +493,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a string type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeString(Fluent $column) @@ -551,7 +503,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a text type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeText(Fluent $column) @@ -562,7 +513,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a medium text type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeMediumText(Fluent $column) @@ -573,7 +523,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a long text type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeLongText(Fluent $column) @@ -584,7 +533,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a big integer type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeBigInteger(Fluent $column) @@ -595,7 +543,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for an integer type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeInteger(Fluent $column) @@ -606,7 +553,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a medium integer type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeMediumInteger(Fluent $column) @@ -617,7 +563,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a tiny integer type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeTinyInteger(Fluent $column) @@ -628,7 +573,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a small integer type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeSmallInteger(Fluent $column) @@ -639,7 +583,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a float type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeFloat(Fluent $column) @@ -650,7 +593,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a double type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeDouble(Fluent $column) @@ -665,7 +607,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a decimal type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeDecimal(Fluent $column) @@ -676,7 +617,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a boolean type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeBoolean(Fluent $column) @@ -687,7 +627,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for an enumeration type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeEnum(Fluent $column) @@ -698,7 +637,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a json type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeJson(Fluent $column) @@ -709,7 +647,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a jsonb type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeJsonb(Fluent $column) @@ -720,7 +657,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a date type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeDate(Fluent $column) @@ -731,7 +667,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a date-time type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeDateTime(Fluent $column) @@ -744,7 +679,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a date-time (with time zone) type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeDateTimeTz(Fluent $column) @@ -755,7 +689,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a time type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeTime(Fluent $column) @@ -766,7 +699,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a time (with time zone) type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeTimeTz(Fluent $column) @@ -777,7 +709,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a timestamp type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeTimestamp(Fluent $column) @@ -790,7 +721,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a timestamp (with time zone) type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeTimestampTz(Fluent $column) @@ -801,7 +731,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a year type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeYear(Fluent $column) @@ -812,7 +741,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a binary type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeBinary(Fluent $column) @@ -823,7 +751,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a uuid type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeUuid(Fluent $column) @@ -834,7 +761,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for an IP address type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeIpAddress(Fluent $column) @@ -845,7 +771,6 @@ class MySqlGrammar extends Grammar /** * Create the column definition for a MAC address type. * - * @param \Hyperf\Utils\Fluent $column * @return string */ protected function typeMacAddress(Fluent $column) @@ -856,13 +781,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a generated virtual column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->virtualAs)) { + if (! is_null($column->virtualAs)) { return " as ({$column->virtualAs})"; } } @@ -870,13 +793,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a generated stored column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyStoredAs(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->storedAs)) { + if (! is_null($column->storedAs)) { return " as ({$column->storedAs}) stored"; } } @@ -884,8 +805,6 @@ class MySqlGrammar extends Grammar /** * Get the SQL for an unsigned column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyUnsigned(Blueprint $blueprint, Fluent $column) @@ -898,13 +817,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a character set column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyCharset(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->charset)) { + if (! is_null($column->charset)) { return ' character set ' . $column->charset; } } @@ -912,13 +829,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a collation column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyCollate(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->collation)) { + if (! is_null($column->collation)) { return " collate '{$column->collation}'"; } } @@ -926,8 +841,6 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a nullable column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyNullable(Blueprint $blueprint, Fluent $column) @@ -940,13 +853,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a default column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyDefault(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->default)) { + if (! is_null($column->default)) { return ' default ' . $this->getDefaultValue($column->default); } } @@ -954,8 +865,6 @@ class MySqlGrammar extends Grammar /** * Get the SQL for an auto-increment column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) @@ -968,13 +877,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a "first" column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyFirst(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->first)) { + if (! is_null($column->first)) { return ' first'; } } @@ -982,13 +889,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for an "after" column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyAfter(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->after)) { + if (! is_null($column->after)) { return ' after ' . $this->wrap($column->after); } } @@ -996,13 +901,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a "comment" column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifyComment(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->comment)) { + if (! is_null($column->comment)) { return " comment '" . addslashes($column->comment) . "'"; } } @@ -1010,13 +913,11 @@ class MySqlGrammar extends Grammar /** * Get the SQL for a SRID column modifier. * - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $column * @return string|null */ protected function modifySrid(Blueprint $blueprint, Fluent $column) { - if (!is_null($column->srid) && is_int($column->srid) && $column->srid > 0) { + if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0) { return ' srid ' . $column->srid; } } @@ -1029,7 +930,7 @@ class MySqlGrammar extends Grammar */ protected function wrapValue($value) { - if ($value !== '*') { + if ('*' !== $value) { return '`' . str_replace('`', '``', $value) . '`'; } diff --git a/src/database/src/Schema/Grammars/RenameColumn.php b/src/database/src/Schema/Grammars/RenameColumn.php index a88b192a3..0b97929a7 100644 --- a/src/database/src/Schema/Grammars/RenameColumn.php +++ b/src/database/src/Schema/Grammars/RenameColumn.php @@ -1,4 +1,5 @@ getDoctrineColumn( - $grammar->getTablePrefix().$blueprint->getTable(), + $grammar->getTablePrefix() . $blueprint->getTable(), $command->from ); @@ -50,11 +48,7 @@ class RenameColumn /** * Get a new column instance with the new column name. * - * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar - * @param \Hyperf\Database\Schema\Blueprint $blueprint - * @param \Hyperf\Utils\Fluent $command - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @param \Hyperf\Database\Schema\Grammars\Grammar $grammar * @return \Doctrine\DBAL\Schema\TableDiff */ protected static function getRenamedDiff(Grammar $grammar, Blueprint $blueprint, Fluent $command, Column $column, SchemaManager $schema) @@ -69,9 +63,6 @@ class RenameColumn /** * Set the renamed columns on the table diff. * - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Hyperf\Utils\Fluent $command - * @param \Doctrine\DBAL\Schema\Column $column * @return \Doctrine\DBAL\Schema\TableDiff */ protected static function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column) diff --git a/src/database/src/Schema/MySqlBuilder.php b/src/database/src/Schema/MySqlBuilder.php index 81106001c..d36dd6d31 100755 --- a/src/database/src/Schema/MySqlBuilder.php +++ b/src/database/src/Schema/MySqlBuilder.php @@ -1,4 +1,5 @@ connection->getTablePrefix().$table; + $table = $this->connection->getTablePrefix() . $table; return count($this->connection->select( $this->grammar->compileTableExists(), @@ -32,12 +33,12 @@ class MySqlBuilder extends Builder /** * Get the column listing for a given table. * - * @param string $table + * @param string $table * @return array */ public function getColumnListing($table) { - $table = $this->connection->getTablePrefix().$table; + $table = $this->connection->getTablePrefix() . $table; $results = $this->connection->select( $this->grammar->compileColumnListing(), @@ -49,8 +50,6 @@ class MySqlBuilder extends Builder /** * Drop all tables from the database. - * - * @return void */ public function dropAllTables() { @@ -77,8 +76,6 @@ class MySqlBuilder extends Builder /** * Drop all views from the database. - * - * @return void */ public function dropAllViews() { @@ -104,7 +101,7 @@ class MySqlBuilder extends Builder * * @return array */ - protected function getAllTables() + public function getAllTables() { return $this->connection->select( $this->grammar->compileGetAllTables() diff --git a/src/db-connection/composer.json b/src/db-connection/composer.json index 2c39bb496..e93bf42b9 100644 --- a/src/db-connection/composer.json +++ b/src/db-connection/composer.json @@ -12,6 +12,7 @@ }, "require": { "php": ">=7.2", + "psr/simple-cache": "^1.0", "hyperf/database": "dev-master", "hyperf/di": "dev-master", "hyperf/event": "dev-master", diff --git a/src/db-connection/src/Cache/Cacheable.php b/src/db-connection/src/Cache/Cacheable.php new file mode 100644 index 000000000..20baa040c --- /dev/null +++ b/src/db-connection/src/Cache/Cacheable.php @@ -0,0 +1,48 @@ +get(Manager::class); + + return $manager->findFromCache($id, static::class); + } + + /** + * @return \Hyperf\Database\Model\Collection + */ + public static function findManyFromCache($ids) + { + $container = ApplicationContext::getContainer(); + $manager = $container->get(Manager::class); + + return $manager->findManyFromCache($ids, static::class); + } + + public function deleteCache() + { + $container = ApplicationContext::getContainer(); + $manager = $container->get(Manager::class); + + return $manager->destroy([$this->getKey()], get_called_class()); + } +} diff --git a/src/db-connection/src/Cache/Config.php b/src/db-connection/src/Cache/Config.php new file mode 100644 index 000000000..7c9d99895 --- /dev/null +++ b/src/db-connection/src/Cache/Config.php @@ -0,0 +1,102 @@ +cacheKey = $values['cache_key']; + } + if (isset($values['prefix'])) { + $this->prefix = $values['prefix']; + } else { + $this->prefix = $name; + } + if (isset($values['ttl'])) { + $this->ttl = $values['ttl']; + } + if (isset($values['load_script'])) { + $this->loadScript = $values['load_script']; + } + } + + public function getCacheKey(): string + { + return $this->cacheKey; + } + + public function setCacheKey(string $cacheKey): Config + { + $this->cacheKey = $cacheKey; + return $this; + } + + public function getPrefix(): string + { + return $this->prefix; + } + + public function setPrefix(string $prefix): Config + { + $this->prefix = $prefix; + return $this; + } + + public function getTtl(): int + { + return $this->ttl; + } + + public function setTtl(int $ttl): Config + { + $this->ttl = $ttl; + return $this; + } + + public function isLoadScript(): bool + { + return $this->loadScript; + } + + public function setLoadScript(bool $loadScript): Config + { + $this->loadScript = $loadScript; + return $this; + } +} diff --git a/src/db-connection/src/Cache/Exception/CacheException.php b/src/db-connection/src/Cache/Exception/CacheException.php new file mode 100644 index 000000000..79a600026 --- /dev/null +++ b/src/db-connection/src/Cache/Exception/CacheException.php @@ -0,0 +1,17 @@ +container = $container; + if (! $container->has(Redis::class)) { + throw new CacheException(sprintf('Entry[%s] of the container is not exist.', Redis::class)); + } + + $this->redis = $container->get(Redis::class); + $this->config = $config; + $this->multiple = new HashsGetMultiple(); + } + + public function get($key, $default = null) + { + $data = $this->redis->hGetAll($key); + if (! $data) { + return $default; + } + + unset($data[$this->defaultKey]); + + if (empty($data)) { + return []; + } + + return $data; + } + + public function set($key, $value, $ttl = null) + { + if (is_array($value)) { + $data = $value; + } elseif ($value instanceof Arrayable) { + $data = $value->toArray(); + } else { + throw new CacheException(sprintf('The value must is array.')); + } + + $data = array_merge($data, [$this->defaultKey => $this->defaultValue]); + $res = $this->redis->hMSet($key, $data); + if ($ttl && $ttl > 0) { + $this->redis->expire($key, $ttl); + } + + return $res; + } + + public function delete($key) + { + return $this->redis->delete($key); + } + + public function clear() + { + throw new CacheException('Method clear is forbidden.'); + } + + public function getMultiple($keys, $default = null) + { + if ($this->config->isLoadScript()) { + $sha = $this->getLuaSha(); + } + + if (! empty($sha)) { + $list = $this->redis->evalSha($sha, $keys, count($keys)); + } else { + $script = $this->multiple->getScript(); + $list = $this->redis->eval($script, $keys, count($keys)); + } + + $result = []; + foreach ($this->multiple->parseResponse($list) as $item) { + unset($item[$this->defaultKey]); + if ($item) { + $result[] = $item; + } + } + + return $result; + } + + public function setMultiple($values, $ttl = null) + { + throw new CacheException('Method setMultiple is forbidden.'); + } + + public function deleteMultiple($keys) + { + return $this->redis->delete(...$keys); + } + + public function has($key) + { + return (bool) $this->redis->exists($key); + } + + public function getConfig(): Config + { + return $this->config; + } + + protected function getLuaSha() + { + if (! empty($this->luaSha)) { + return $this->luaSha; + } + + $sha = $this->redis->script('load', $this->multiple->getScript()); + + return $this->luaSha = $sha; + } +} diff --git a/src/db-connection/src/Cache/Listener/DeleteCacheListener.php b/src/db-connection/src/Cache/Listener/DeleteCacheListener.php new file mode 100644 index 000000000..66f8b4e6f --- /dev/null +++ b/src/db-connection/src/Cache/Listener/DeleteCacheListener.php @@ -0,0 +1,47 @@ +getModel(); + if (method_exists($model, 'deleteCache')) { + $model->deleteCache(); + } + } + } +} diff --git a/src/db-connection/src/Cache/Manager.php b/src/db-connection/src/Cache/Manager.php new file mode 100644 index 000000000..655d54f5f --- /dev/null +++ b/src/db-connection/src/Cache/Manager.php @@ -0,0 +1,174 @@ +container = $container; + $this->logger = $container->get(StdoutLoggerInterface::class); + $config = $container->get(ConfigInterface::class); + if (! $config->has('databases')) { + throw new \InvalidArgumentException('config databases is not exist!'); + } + + foreach ($config->get('databases') as $key => $item) { + $handler = $item['handler'] ?? RedisHandler::class; + $config = new Config($item['cache'] ?? [], $key); + $this->handlers[$key] = new $handler($this->container, $config); + } + } + + public function findFromCache($id, string $class) + { + /** @var Model $instance */ + $instance = new $class(); + + $name = $instance->getConnectionName(); + $primaryKey = $instance->getKeyName(); + + if ($handler = $this->handlers[$name] ?? null) { + $key = $this->getCacheKey($id, $instance, $handler->getConfig()); + $data = $handler->get($key); + if ($data) { + return $instance->newInstance($data, true); + } + + // Fetch it from database, because it not exist in cache handler. + if (is_null($data)) { + $model = $instance->newQuery()->where($primaryKey, '=', $id)->first(); + if ($model) { + $handler->set($key, $model->toArray()); + } else { + $handler->set($key, []); + } + return $model; + } + + // It not exist in cache handler and database. + return null; + } + + $this->logger->alert('Cache handler not exist, fetch data from database.'); + return $instance->newQuery()->where($primaryKey, '=', $id)->first(); + } + + public function findManyFromCache(array $ids, string $class) + { + /** @var Model $instance */ + $instance = new $class(); + + $name = $instance->getConnectionName(); + $primaryKey = $instance->getKeyName(); + + if ($handler = $this->handlers[$name] ?? null) { + $keys = []; + foreach ($ids as $id) { + $keys[] = $this->getCacheKey($id, $instance, $handler->getConfig()); + } + $data = $handler->getMultiple($keys); + $items = []; + $fetchIds = []; + foreach ($data ?? [] as $item) { + if (isset($item[$primaryKey])) { + $items[] = $item; + $fetchIds[] = $item[$primaryKey]; + } + } + + // Get ids that not exist in cache handler. + $targetIds = array_diff($ids, $fetchIds); + $models = $instance->newQuery()->whereIn($primaryKey, $targetIds)->get(); + /** @var Model $model */ + foreach ($models as $model) { + $id = $model->getKey(); + $key = $this->getCacheKey($id, $instance, $handler->getConfig()); + $handler->set($key, $model->toArray()); + } + + $items = array_merge($items, $models->toArray()); + $map = []; + foreach ($items as $item) { + $map[$item[$primaryKey]] = $item; + } + + $result = []; + foreach ($ids as $id) { + if (isset($map[$id])) { + $result[] = $map[$id]; + } + } + + return $instance->hydrate($result); + } + + $this->logger->alert('Cache handler not exist, fetch data from database.'); + return $instance->newQuery()->whereIn($primaryKey, $ids)->get(); + } + + /** + * Destroy the models for the given IDs from cache. + */ + public function destroy($ids, string $class) + { + /** @var Model $instance */ + $instance = new $class(); + + $name = $instance->getConnectionName(); + if ($handler = $this->handlers[$name] ?? null) { + $keys = []; + foreach ($ids as $id) { + $keys[] = $this->getCacheKey($id, $instance, $handler->getConfig()); + } + + return $handler->deleteMultiple($keys); + } + + return 0; + } + + protected function getCacheKey($id, Model $model, Config $config) + { + // mc:$prefix:m:$model:$pk:$id + return sprintf( + $config->getCacheKey(), + $config->getPrefix(), + $model->getTable(), + $model->getKeyName(), + $id + ); + } +} diff --git a/src/db-connection/src/Cache/Redis/HashsGetMultiple.php b/src/db-connection/src/Cache/Redis/HashsGetMultiple.php new file mode 100644 index 000000000..410d089b4 --- /dev/null +++ b/src/db-connection/src/Cache/Redis/HashsGetMultiple.php @@ -0,0 +1,49 @@ + SqlServerConnector::class, ], 'commands' => [ + ModelCommand::class ], 'scan' => [ 'paths' => [ diff --git a/src/db-connection/src/Model/Model.php b/src/db-connection/src/Model/Model.php index 7dc4d83fb..66b650c05 100644 --- a/src/db-connection/src/Model/Model.php +++ b/src/db-connection/src/Model/Model.php @@ -43,7 +43,7 @@ class Model extends BaseModel } /** - * @throws RuntimeException When the model does not define the repository class. + * @throws RuntimeException when the model does not define the repository class */ public function getRepository() {