Skip to content

Commit 27356b4

Browse files
authored
Merge pull request #1023 from cakephp/3.next-merge
merge 3.x => 3.next
2 parents db037f5 + 8673a0d commit 27356b4

39 files changed

+497
-200
lines changed

.phive/phars.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpstan" version="1.11.9" installed="1.11.9" location="./tools/phpstan" copy="false"/>
4-
<phar name="psalm" version="5.25.0" installed="5.25.0" location="./tools/psalm" copy="false"/>
3+
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
4+
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
55
</phive>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": ">=8.1",
2424
"brick/varexporter": "^0.5.0",
25-
"cakephp/cakephp": "dev-5.next as 5.1.0",
25+
"cakephp/cakephp": "^5.1",
2626
"cakephp/twig-view": "^2.0.0",
2727
"nikic/php-parser": "^5.0.0"
2828
},

docs/en/development.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ looks like this::
129129
/**
130130
* Hook method for defining this command's option parser.
131131
*
132-
* @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options
132+
* @see https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
133133
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
134134
* @return \Cake\Console\ConsoleOptionParser The built parser.
135135
*/
@@ -172,7 +172,7 @@ And the resultant baked class (**src/Command/FooCommand.php**) looks like this::
172172
/**
173173
* Hook method for defining this command's option parser.
174174
*
175-
* @see https://book.cakephp.org/4/en/console-commands/commands.html#defining-arguments-and-options
175+
* @see https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
176176
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
177177
* @return \Cake\Console\ConsoleOptionParser The built parser.
178178
*/

docs/en/usage.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ You can get the list of available bake command by running ``bin/cake bake --help
5252
To run a command, type `cake command_name [args|options]`
5353
To get help on a specific command, type `cake command_name --help`
5454

55+
Bake Models
56+
===========
57+
58+
Models are generically baked from the existing DB tables.
59+
The conventions here apply, so it will detect relations based on ``thing_id`` foreign keys to ``things`` tables with their ``id`` primary keys.
60+
61+
For non-conventional relations, you can use references in the constraints / foreign key definitions for Bake to detect the relations, e.g.::
62+
63+
->addForeignKey('billing_country_id', 'countries') // defaults to `id`
64+
->addForeignKey('shipping_country_id', 'countries', 'cid')
65+
66+
5567
Bake Themes
5668
===========
5769

docs/fr/development.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ ressemble à ceci::
137137
/**
138138
* Méthode hook pour définir le parseur d'option de cette commande.
139139
*
140-
* @see https://book.cakephp.org/4/fr/console-commands/commands.html#defining-arguments-and-options
140+
* @see https://book.cakephp.org/5/fr/console-commands/commands.html#defining-arguments-and-options
141141
* @param \Cake\Console\ConsoleOptionParser $parser Le parseur à définir
142142
* @return \Cake\Console\ConsoleOptionParser Le parseur construit.
143143
*/
@@ -181,7 +181,7 @@ ressemble à ceci::
181181
/**
182182
* Méthode hook pour définir le parseur d'option de cette commande.
183183
*
184-
* @see https://book.cakephp.org/4/fr/console-commands/commands.html#defining-arguments-and-options
184+
* @see https://book.cakephp.org/5/fr/console-commands/commands.html#defining-arguments-and-options
185185
* @param \Cake\Console\ConsoleOptionParser $parser Le parseur à définir
186186
* @return \Cake\Console\ConsoleOptionParser Le parseur construit.
187187
*/

phpstan-baseline.neon

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Instanceof between mixed and Cake\\\\Chronos\\\\Chronos will always evaluate to false\\.$#"
4+
message: '#^Method Bake\\BakePlugin\:\:bootstrap\(\) has parameter \$app with generic interface Cake\\Core\\PluginApplicationInterface but does not specify its types\: TSubject$#'
5+
identifier: missingType.generics
6+
count: 1
7+
path: src/BakePlugin.php
8+
9+
-
10+
message: '#^Instanceof between mixed and Cake\\Chronos\\Chronos will always evaluate to false\.$#'
11+
identifier: instanceof.alwaysFalse
512
count: 1
613
path: src/Command/FixtureCommand.php
714

815
-
9-
message: "#^Dead catch \\- UnexpectedValueException is never thrown in the try block\\.$#"
16+
message: '#^Dead catch \- UnexpectedValueException is never thrown in the try block\.$#'
17+
identifier: catch.neverThrown
1018
count: 1
1119
path: src/Command/TestCommand.php

src/BakePlugin.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class BakePlugin extends BasePlugin
5050
/**
5151
* Load the TwigView plugin.
5252
*
53-
* @phpstan-ignore-next-line
5453
* @param \Cake\Core\PluginApplicationInterface $app The host application
5554
* @return void
5655
*/
@@ -138,22 +137,20 @@ protected function findInPath(string $namespace, string $path): array
138137
if ($item->isDot() || $item->isDir()) {
139138
continue;
140139
}
141-
/** @psalm-var class-string<\Bake\Command\BakeCommand> $class */
142140
$class = $namespace . $item->getBasename('.php');
143141

144142
if (!$hasSubfolder) {
145143
try {
146144
$reflection = new ReflectionClass($class);
147-
/** @phpstan-ignore-next-line */
148-
} catch (ReflectionException $e) {
145+
} catch (ReflectionException) {
149146
continue;
150147
}
151-
/** @psalm-suppress TypeDoesNotContainType */
152148
if (!$reflection->isInstantiable() || !$reflection->isSubclassOf(BakeCommand::class)) {
153149
continue;
154150
}
155151
}
156152

153+
/** @var class-string<\Bake\Command\BakeCommand> $class */
157154
$candidates[$class::defaultName()] = $class;
158155
}
159156

src/Command/AllCommand.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Cake\Console\ConsoleIo;
2222
use Cake\Console\ConsoleOptionParser;
2323
use Cake\Datasource\ConnectionManager;
24+
use Throwable;
2425

2526
/**
2627
* Command for `bake all`
@@ -49,7 +50,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
4950
$parser = $this->_setCommonOptions($parser);
5051

5152
$parser = $parser->setDescription(
52-
'Generate the model, controller, template, tests and fixture for a table.'
53+
'Generate the model, controller, template, tests and fixture for a table.',
5354
)->addArgument('name', [
5455
'help' => 'Name of the table to generate code for.',
5556
])->addOption('everything', [
@@ -83,20 +84,21 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
8384
/** @var \Cake\Database\Connection $connection */
8485
$connection = ConnectionManager::get($this->connection);
8586
$scanner = new TableScanner($connection);
86-
if (empty($name) && !$args->getOption('everything')) {
87+
$tables = $scanner->removeShadowTranslationTables($scanner->listUnskipped());
88+
89+
if (!$name && !$args->getOption('everything')) {
8790
$io->out('Choose a table to generate from the following:');
88-
foreach ($scanner->listUnskipped() as $table) {
91+
foreach ($tables as $table) {
8992
$io->out('- ' . $this->_camelize($table));
9093
}
9194

9295
return static::CODE_SUCCESS;
9396
}
94-
if ($args->getOption('everything')) {
95-
$tables = $scanner->listUnskipped();
96-
} else {
97+
if (!$args->getOption('everything')) {
9798
$tables = [$name];
9899
}
99100

101+
$errors = 0;
100102
foreach ($this->commands as $commandName) {
101103
/** @var \Cake\Command\Command $command */
102104
$command = new $commandName();
@@ -113,12 +115,27 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
113115
foreach ($tables as $table) {
114116
$parser = $command->getOptionParser();
115117
$subArgs = new Arguments([$table], $options, $parser->argumentNames());
116-
$command->execute($subArgs, $io);
118+
119+
try {
120+
$command->execute($subArgs, $io);
121+
} catch (Throwable $e) {
122+
if (!$args->getOption('everything') || !$args->getOption('force')) {
123+
throw $e;
124+
}
125+
126+
$message = sprintf('Error generating %s for %s: %s', $commandName, $table, $e->getMessage());
127+
$io->err('<error>' . $message . '</error>');
128+
$errors++;
129+
}
117130
}
118131
}
119132

120-
$io->out('<success>Bake All complete.</success>', 1, ConsoleIo::NORMAL);
133+
if ($errors) {
134+
$io->out(sprintf('<warning>Bake All completed, but with %s errors.</warning>', $errors), 1, ConsoleIo::NORMAL);
135+
} else {
136+
$io->out('<success>Bake All complete.</success>', 1, ConsoleIo::NORMAL);
137+
}
121138

122-
return static::CODE_SUCCESS;
139+
return $errors ? static::CODE_ERROR : static::CODE_SUCCESS;
123140
}
124141
}

src/Command/FixtureAllCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
8686
$connection = ConnectionManager::get($args->getOption('connection') ?? 'default');
8787
$scanner = new TableScanner($connection);
8888
$fixture = new FixtureCommand();
89-
foreach ($scanner->listUnskipped() as $table) {
89+
90+
$tables = $scanner->removeShadowTranslationTables($scanner->listUnskipped());
91+
foreach ($tables as $table) {
9092
$fixtureArgs = new Arguments([$table], $args->getOptions(), ['name']);
9193
$fixture->execute($fixtureArgs, $io);
9294
}

src/Command/ModelAllCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
8383
/** @var \Cake\Database\Connection $connection */
8484
$connection = ConnectionManager::get($this->connection);
8585
$scanner = new TableScanner($connection);
86-
foreach ($scanner->listUnskipped() as $table) {
86+
$tables = $scanner->removeShadowTranslationTables($scanner->listUnskipped());
87+
foreach ($tables as $table) {
8788
$this->getTableLocator()->clear();
8889
$modelArgs = new Arguments([$table], $args->getOptions(), ['name']);
8990
$this->modelCommand->execute($modelArgs, $io);

0 commit comments

Comments
 (0)