Merge remote-tracking branch 'upstream/develop' into 4.5

Conflicts:
	phpstan-baseline.php
This commit is contained in:
kenjis 2024-01-31 08:22:01 +09:00
commit dfdc101aad
No known key found for this signature in database
GPG Key ID: BD254878922AF198
13 changed files with 189 additions and 143 deletions

View File

@ -32,7 +32,7 @@
"phpunit/phpcov": "^8.2",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1 || ^2.0",
"rector/rector": "0.19.2",
"rector/rector": "0.19.5",
"vimeo/psalm": "^5.0"
},
"replace": {

View File

@ -2,19 +2,27 @@
## Contributions
We expect all contributions to conform to our
[style guide](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/styleguide.md),
be commented (inside the PHP source files), be documented (in the
[user guide](https://codeigniter4.github.io/userguide/)), and unit tested (in
the [test folder](https://github.com/codeigniter4/CodeIgniter4/tree/develop/tests)).
We expect all contributions to
- conform to our [style guide](./styleguide.md),
- be commented (inside the PHP source files),
- be documented (in the [user guide](https://codeigniter4.github.io/userguide/)),
- and unit tested (in the [test folder](https://github.com/codeigniter4/CodeIgniter4/tree/develop/tests)).
Note, we expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite
to prove the code works. If pull requests are not accompanied by relevant tests, they will likely be closed.
Since we are a team of volunteers, we don't have any more time to work on the framework than you do. Please
make it as painless for your contributions to be included as possible. If you need help with getting tests
running on your local machines, ask for help on the forums. We would be happy to help out.
> [!IMPORTANT]
> We expect all code changes or bug-fixes to be accompanied by one or more tests
> added to our test suite to prove the code works.
The [Open Source Guide](https://opensource.guide/) is a good first read for those new to contributing to open source!
If pull requests are not accompanied by relevant tests, they will likely be closed.
Since we are a team of volunteers, we don't have any more time to work on the
framework than you do. Please make it as painless for your contributions to be
included as possible.
If you need help with getting tests running on your local machines, ask for help
on the [forum](https://forum.codeigniter.com/forumdisplay.php?fid=27). We would
be happy to help out.
The [Open Source Guide](https://opensource.guide/) is a good first read for those
new to contributing to open source!
## CodeIgniter Internals Overview
@ -29,7 +37,8 @@ Your Pull Requests (PRs) need to meet our guidelines.
If your Pull Requests fail to pass these guidelines, they will be declined,
and you will need to re-submit when you've made the changes.
This might sound a bit tough, but it is required for us to maintain the quality of the codebase.
This might sound a bit tough, but it is required for us to maintain the quality
of the codebase.
### PHP Style
@ -38,10 +47,11 @@ This might sound a bit tough, but it is required for us to maintain the quality
All code must conform to our [Style Guide](./styleguide.md), which is
based on PSR-12.
This makes certain that all submitted code is of the same format
as the existing code and ensures that the codebase will be as readable as possible.
This makes certain that all submitted code is of the same format as the existing
code and ensures that the codebase will be as readable as possible.
You can fix most of the coding style violations by running this command in your terminal:
You can fix most of the coding style violations by running this command in your
terminal:
```console
composer cs-fix
@ -55,7 +65,8 @@ composer cs
### Unit Testing
If you are not familiar with Unit Testing, see [the forum thread](https://forum.codeigniter.com/showthread.php?tid=81830).
If you are not familiar with Unit Testing, see
[the forum thread](https://forum.codeigniter.com/showthread.php?tid=81830).
Unit testing is expected for all CodeIgniter components. We use PHPUnit,
and run unit tests using GitHub Actions for each PR submitted or changed.
@ -93,7 +104,7 @@ See the following for more information.
Do not add comments that are superficial, duplicated, or stating the obvious.
### Documentation
### User Guide
The User Guide is an essential component of the CodeIgniter framework.
@ -106,18 +117,21 @@ then you will need to add to the documentation.
New classes, methods, parameters, changing default values, changing behavior etc.
are all changes that require a change to documentation.
Also, the [Changelog](https://codeigniter4.github.io/CodeIgniter4/changelogs/index.html) must be updated for every change,
and [PHPDoc](https://github.com/codeigniter4/CodeIgniter4/blob/develop/phpdoc.dist.xml) blocks must be maintained.
Also, the [Changelog](https://codeigniter4.github.io/CodeIgniter4/changelogs/index.html)
must be updated for every change, and PHPDoc blocks must be maintained.
See [Writing CodeIgniter Documentation](./documentation.rst).
#### Changelog
The [Changelog](https://codeigniter4.github.io/CodeIgniter4/changelogs/index.html), in the user guide, needs to be kept up-to-date. Not
all changes will need an entry in it, but the following items should.
The [Changelog](https://codeigniter4.github.io/CodeIgniter4/changelogs/index.html)
in the [user guide](https://github.com/codeigniter4/CodeIgniter4/tree/develop/user_guide_src/source/changelogs)
needs to be kept up-to-date. Not all changes will need an entry in it, but the
following items should.
- all breaking changes (BCs)
- all enhancements (new features, new classes, new APIs)
- message changes
- other behavior changes
- deprecations
- major bug fixes
@ -127,11 +141,12 @@ all changes will need an entry in it, but the following items should.
If your PR requires users to do something when they upgrade CodeIgniter, or
changes the Config values,
the [Upgrading Guide](https://codeigniter4.github.io/CodeIgniter4/installation/upgrading.html)
is also needed.
in the [installation](https://github.com/codeigniter4/CodeIgniter4/tree/develop/user_guide_src/source/installation)
folder is also needed.
- Add an instruction what to do when upgrading.
- If you add new properties or changes default values in Config files, add the
changes in *"Project Files > Content Changes > Config"*.
changes in *"Project Files > Content Changes > Config"*.
### CSS
@ -154,12 +169,19 @@ break with earlier versions of the framework.
#### Breaking Changes
In general, any change that would disrupt existing uses of the framework is considered a "Breaking Change" (BC) and will not be favorably considered. A few specific examples to pay attention to:
In general, any change that would disrupt existing uses of the framework is
considered a "Breaking Change" (BC) and will not be favorably considered. A few
specific examples to pay attention to:
1. New classes/properties/constants in `system` are acceptable, but anything in the `app` directory that will be used in `system` should be backwards-compatible.
2. Any changes to non-private methods must be backwards-compatible with the original definition.
3. Deleting non-private properties or methods without prior deprecation notices is frowned upon and will likely be closed.
4. Deleting or renaming public classes and interfaces, as well as those not marked as `@internal`, without prior deprecation notices or not providing fallback solutions will also not be favorably considered.
1. New classes/properties/constants in `system` are acceptable, but anything in
the `app` directory that will be used in `system` should be backwards-compatible.
2. Any changes to non-private methods must be backwards-compatible with the original
definition.
3. Deleting non-private properties or methods without prior deprecation notices
is frowned upon and will likely be closed.
4. Deleting or renaming public classes and interfaces, as well as those not marked
as `@internal`, without prior deprecation notices or not providing fallback
solutions will also not be favorably considered.
### Mergeability
@ -174,30 +196,36 @@ working on your contribution.
### Branching
All bug fixes should be sent to the __"develop"__ branch, this is where the next bug fix version will be developed.
All bug fixes should be sent to the __"develop"__ branch, this is where the next
bug fix version will be developed.
PRs with any enhancement should be sent to next minor version branch, e.g. __"4.3"__
PRs with any enhancement should be sent to next minor version branch, e.g. __"4.5"__
The __"master"__ branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g. an
emergency security patch) can be applied to the "master" branch to create a new version, without worrying
about other features holding it up. Any sent to the "master" branch will be closed automatically.
The __"master"__ branch will always contain the latest stable version and is kept
clean so a "hotfix" (e.g. an emergency security patch) can be applied to the
"master" branch to create a new version, without worrying about other features
holding it up. Any sent to the "master" branch will be closed automatically.
If you have multiple changes to submit,
please place all changes into their own branch on your fork.
**One thing at a time:** A pull request should only contain one change. That does not mean only one commit,
but one change - however many commits it took. The reason for this is that if you change X and Y,
but send a pull request for both at the same time, we might really want X but disagree with Y,
meaning we cannot merge the request. Using the Git-Flow branching model you can create new
branches for both of these features and send two requests.
**One thing at a time:** A pull request should only contain one change. That does
not mean only one commit, but one change - however many commits it took. The reason
for this is that if you change X and Y, but send a pull request for both at the
same time, we might really want X but disagree with Y, meaning we cannot merge
the request. Using the Git-Flow branching model you can create new branches for
both of these features and send two requests.
A reminder: **please use separate branches for each of your PRs** - it will make it easier for you to keep
changes separate from each other and from whatever else you are doing with your repository!
> [!IMPORTANT]
> **Please use separate branches for each of your PRs** - it will make it easier
> for you to keep changes separate from each other and from whatever else you are
> doing with your repository!
### Signing
You must [GPG-sign](./signing.md) your work, certifying that you either wrote the work or
otherwise have the right to pass it on to an open-source project. See [Developer's Certificate of Origin](./DCO.md).
otherwise have the right to pass it on to an open-source project. See
[Developer's Certificate of Origin](./DCO.md).
This is *not* just a "signed-off-by" commit, but instead, a digitally signed one.
@ -205,17 +233,20 @@ See [Contribution signing](./signing.md) for details.
### Static Analysis on PHP code
We cannot, at all times, guarantee that all PHP code submitted on pull requests to be working well without
actually running the code. For this reason, we make use of two static analysis tools, [PHPStan][1]
and [Rector][2] to do the analysis for us.
We cannot, at all times, guarantee that all PHP code submitted on pull requests
to be working well without actually running the code. For this reason, we make
use of two static analysis tools, [PHPStan][1] and [Rector][2] to do the analysis
for us.
These tools have already been integrated into our CI/CD workflow to minimize unannounced bugs. Pull requests
are expected that their code will pass these two. In your local machine, you can manually run these tools
so that you can fix whatever errors that pop up with your submission.
These tools have already been integrated into our CI/CD workflow to minimize
unannounced bugs. Pull requests are expected that their code will pass these two.
In your local machine, you can manually run these tools so that you can fix
whatever errors that pop up with your submission.
#### PHPStan
PHPStan is expected to scan the entire framework by running this command in your terminal:
PHPStan is expected to scan the entire framework by running this command in your
terminal:
```console
vendor/bin/phpstan analyse
@ -252,7 +283,10 @@ vendor/bin/rector process path/to/file
## How-to Guide
The best way to contribute is to fork the CodeIgniter4 repository, and "clone" that to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it".
The best way to contribute is to fork the CodeIgniter4 repository, and "clone"
that to your development area. That sounds like some jargon, but "forking" on
GitHub means "making a copy of that repo to your account" and "cloning" means
"copying that code to your environment so you can work on it".
1. Set up Git ([Windows](https://git-scm.com/download/win), [Mac](https://git-scm.com/download/mac), & [Linux](https://git-scm.com/download/linux)).
2. Go to the [CodeIgniter4 repository](https://github.com/codeigniter4/CodeIgniter4).
@ -266,16 +300,21 @@ The best way to contribute is to fork the CodeIgniter4 repository, and "clone" t
- If your PR is for bug fixes:
- `> git switch develop`
- `> git switch -c <new-branch-name>`
- If your PR has any enhancement, create new branch from next minor version branch, e.g. __"4.3"__:
- If your PR has any enhancement, create new branch from next minor version branch, e.g. __"4.5"__:
- `> git switch <next-minor-version-branch>`
- `> git switch -c <new-branch-name>`
7. Fix existing bugs on the [Issue tracker](https://github.com/codeigniter4/CodeIgniter4/issues) after confirming that no one else is working on them.
7. Fix existing bugs on the [Issue tracker](https://github.com/codeigniter4/CodeIgniter4/issues) after confirming that no one
else is working on them.
8. [Commit](https://help.github.com/en/desktop/contributing-to-projects/committing-and-reviewing-changes-to-your-project) the changed files in your contribution branch.
- `> git commit`
- Commit messages are expected to be descriptive of why and what you changed specifically. Commit messages like "Fixes #1234" would be asked by the reviewer to be revised. [Atomic commit](https://en.wikipedia.org/wiki/Atomic_commit#Atomic_commit_convention) is recommended. See [Contribution Workflow](./workflow.md#commit-messages) for details.
- Commit messages are expected to be descriptive of why and what you changed
specifically. Commit messages like "Fixes #1234" would be asked by the reviewer
to be revised. [Atomic commit](https://en.wikipedia.org/wiki/Atomic_commit#Atomic_commit_convention) is recommended. See
[Contribution Workflow](./workflow.md#commit-messages) for details.
9. If you have touched PHP code, run static analysis.
- `> composer analyze`
10. Run unit tests on the specific file you modified. If there are no existing tests yet, please create one.
10. Run unit tests on the specific file you modified. If there are no existing
tests yet, please create one.
- `> vendor/bin/phpunit tests/system/path/to/file/you/modified`
- Make sure the tests pass to have a higher chance of merging.
11. [Push](https://docs.github.com/en/github/using-git/pushing-commits-to-a-remote-repository) your contribution branch to your fork.
@ -285,9 +324,13 @@ The best way to contribute is to fork the CodeIgniter4 repository, and "clone" t
See [Contribution workflow](./workflow.md) for Git workflow details.
The codebase maintainers will now be alerted to the submission and someone from the team will respond. If your change fails to meet the guidelines, it will be rejected or feedback will be provided to help you improve it.
The codebase maintainers will now be alerted to the submission and someone from
the team will respond. If your change fails to meet the guidelines, it will be
rejected or feedback will be provided to help you improve it.
Once the maintainer handling your pull request is satisfied with it, they will approve the pull request and merge it into the "develop" branch. Your patch will now be part of the next release!
Once the maintainer handling your pull request is satisfied with it, they will
approve the pull request and merge it into the "develop" branch. Your patch will
now be part of the next release!
## Translating System Messages

View File

@ -3,7 +3,7 @@
This document declares a set of coding conventions and rules to be followed when contributing PHP code
to the CodeIgniter project.
**Note:**
> [!NOTE]
> While we would recommend it, there's no requirement that you follow these conventions and rules in your
own projects. Usage is discretionary within your projects but strictly enforceable within the framework.
@ -200,7 +200,7 @@ conditions MUST always be at the beginning or at the end of the line, not a mix
- The conditional operator, also known simply as the ternary operator, MUST be preceded and followed by at least one space around both the `?` and `:` characters.
- When the middle operand of the conditional operator is omitted, the operator MUST follow the same style rules as other binary comparison operators.
**Note:**
> [!NOTE]
> All the preceding rules are quoted from PSR-12. You may visit its website to view the code block samples.
## Custom Conventions

View File

@ -16,8 +16,9 @@ values for when you try these:
## Branching
- All bug fix PRs should be sent to the __"develop"__ branch, this is where the next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __"4.3"__
- All bug fix PRs should be sent to the __"develop"__ branch, this is where the
next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __"4.5"__
The "master" branch will always contain the latest stable
version and is kept clean so a "hotfix" (e.g: an emergency security
@ -111,23 +112,25 @@ This local branch should be named appropriately, for instance
"fix/problem123" or "new/mind-reader". The slashes in these branch names
is optional, and implies a sort of namespacing if used.
- All bug fix PRs should be sent to the __"develop"__ branch, this is where the next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __"4.3"__
- All bug fix PRs should be sent to the __"develop"__ branch, this is where the
next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __"4.5"__
For instance, if you send a PR to __"develop"__ branch, make sure you are in the *develop* branch, and create a
new bugfix branch, based on *develop*, for a new feature you are
creating:
For instance, if you send a PR to __"develop"__ branch, make sure you are in the
*develop* branch, and create a new bugfix branch, based on *develop*, for a new
feature you are creating:
```console
> git switch develop
> git switch -c fix/problem123
```
If you send a PR with an enhancement, make sure you are in the *next minor version* branch,
and create a new feature branch, based on, e.g., *4.3*, for a new feature you are creating:
If you send a PR with an enhancement, make sure you are in the *next minor version*
branch, and create a new feature branch, based on, e.g., __"4.5"__, for a new
feature you are creating:
```console
> git switch 4.3
> git switch 4.5
> git switch -c new/mind-reader
```
@ -151,14 +154,14 @@ There are some references for writing good commit messages:
If there are intermediate commits that are not meaningful to the overall PR,
such as "Fix error on style guide", "Fix phpstan error", "Fix mistake in code",
and other related commits, you can squash your commits so that we can have a clean commit history.
But it is not a must.
and other related commits, you can squash your commits so that we can have a
clean commit history. But it is not a must.
### Commit Messages
Commit messages are important. They communicate the intent of a specific change, concisely.
They make it easier to review code, and to find out why a change was made
if the code history is examined later.
Commit messages are important. They communicate the intent of a specific change,
concisely. They make it easier to review code, and to find out why a change was
made if the code history is examined later.
The audience for your commit messages will be the codebase maintainers,
any code reviewers, and debuggers trying to figure out when a bug might
@ -166,8 +169,9 @@ have been introduced.
Make your commit messages meaningful.
Commit messages are expected to be descriptive of **why** and what you changed specifically.
Commit messages like "Fixes #1234" would be asked by the reviewer to be revised.
Commit messages are expected to be descriptive of **why** and what you changed
specifically. Commit messages like "Fixes #1234" would be asked by the reviewer
to be revised.
You can have as many commits in a branch as you need to "get it right".
For instance, to commit your work from a debugging session:
@ -185,7 +189,8 @@ Just make sure that your commits in a feature branch are all related.
### GPG-Signing Old Commits
Any developer can forget GPG-signing their commits with the option `-S`, like `git commit -S -m 'Signed GPG'`. In such a case, all you need to do is the following:
Any developer can forget GPG-signing their commits with the option `-S`, like
`git commit -S -m 'Signed GPG'`. In such a case, all you need to do is the following:
Latest commit only:
```console
@ -235,7 +240,7 @@ are working in.
At some point, you will decide that your feature branch is complete, or
that it could benefit from a review by fellow developers.
> **Note**
> [!NOTE]
> Remember to sync your local repo with the shared one before pushing!
It is a lot easier to resolve conflicts at this stage.
@ -267,16 +272,16 @@ On GitHub, you propose your changes one feature branch at a time, by
switching to the branch you wish to contribute, and then clicking on
"New pull request".
Make sure the pull request is for the shared __"develop"__ or next minor version branch, e.g. __"4.3"__, or it
may be rejected.
Make sure the pull request is for the shared __"develop"__ or next minor version
branch, e.g. __"4.5"__, or it may be rejected.
Make sure that the PR title is helpful for the maintainers and other
developers. Add any comments appropriate, for instance asking for
review.
> **Note**
> If you do not provide a title or description for your PR, the odds of it being summarily rejected
rise astronomically.
> [!NOTE]
> If you do not provide a title or description for your PR, the odds of it being
> summarily rejected rise astronomically.
When your PR is submitted, a continuous integration task will be
triggered, running all the unit tests as well as any other checking we
@ -306,9 +311,11 @@ And if your PRs have the breaking changes, label the following label:
## Updating Your Branch
If you are asked for changes in the review, commit the fix in your branch and push it to GitHub again.
If you are asked for changes in the review, commit the fix in your branch and
push it to GitHub again.
If the __"develop"__ or next minor version branch, e.g. __"4.3"__, progresses and conflicts arise that prevent merging, or if you are asked to *rebase*,
If the __"develop"__ or next minor version branch, e.g. __"4.5"__, progresses
and conflicts arise that prevent merging, or if you are asked to *rebase*,
do the following:
Synchronize your repository:
@ -347,7 +354,7 @@ And finally push your local branch to your GitHub repository:
If you have sent a PR to the wrong branch, you need to create a new PR branch.
When you have the PR branch `feat-abc` and you should have sent the PR to `4.3`,
When you have the PR branch `feat-abc` and you should have sent the PR to __"4.5"__,
but you created the PR branch from `develop` and sent a PR.
Copy the IDs of any commits you made that you want to keep:
@ -356,13 +363,13 @@ Copy the IDs of any commits you made that you want to keep:
> git log
```
Update your `4.3` branch:
Update your __"4.5"__ branch:
```console
> git fetch upstream
> git switch 4.3
> git merge upstream/4.3
> git push origin 4.3
> git switch 4.5
> git merge upstream/4.5
> git push origin 4.5
```
(Optional) Create a new branch as a backup, just in case:
@ -371,10 +378,10 @@ Update your `4.3` branch:
> git branch feat-abc.bk feat-abc
```
Rebase your PR branch from `develop` onto `4.3`:
Rebase your PR branch from `develop` onto __"4.5"__:
```console
> git rebase --onto 4.3 develop feat-abc
> git rebase --onto 4.5 develop feat-abc
```
Force push.
@ -383,7 +390,7 @@ Force push.
> git push --force-with-lease origin feat-abc
```
On the GitHub PR page, change the base branch to the correct branch `4.3`.
On the GitHub PR page, change the base branch to the correct branch __"4.5"__.
## Cleanup

View File

@ -2826,21 +2826,6 @@ $ignoreErrors[] = [
'count' => 1,
'path' => __DIR__ . '/system/Test/PhpStreamWrapper.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Test\\\\TestLogger\\:\\:cleanup\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/TestLogger.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$level \\(string\\) of method CodeIgniter\\\\Test\\\\TestLogger\\:\\:log\\(\\) should be contravariant with parameter \\$level \\(mixed\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/TestLogger.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Test\\\\TestLogger\\:\\:\\$op_logs has no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/TestLogger.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Throttle\\\\Throttler\\:\\:\\$testTime \\(int\\) on left side of \\?\\? is not nullable\\.$#',
'count' => 1,

View File

@ -317,8 +317,8 @@ class Connection extends BaseConnection
$retval[$i]->max_length = $length;
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
$retval[$i]->nullable = $query[$i]->NULLABLE === 'Y';
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
}
return $retval;

View File

@ -320,9 +320,9 @@ class Connection extends BaseConnection
$retVal[$i]->name = $query[$i]->column_name;
$retVal[$i]->type = $query[$i]->data_type;
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
$retVal[$i]->nullable = $query[$i]->is_nullable === 'YES';
$retVal[$i]->default = $query[$i]->column_default;
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
}
return $retVal;

View File

@ -359,15 +359,15 @@ class Connection extends BaseConnection
for ($i = 0, $c = count($query); $i < $c; $i++) {
$retVal[$i] = new stdClass();
$retVal[$i]->name = $query[$i]->COLUMN_NAME;
$retVal[$i]->type = $query[$i]->DATA_TYPE;
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
$retVal[$i]->name = $query[$i]->COLUMN_NAME;
$retVal[$i]->type = $query[$i]->DATA_TYPE;
$retVal[$i]->max_length = $query[$i]->CHARACTER_MAXIMUM_LENGTH > 0
? $query[$i]->CHARACTER_MAXIMUM_LENGTH
: $query[$i]->NUMERIC_PRECISION;
$retVal[$i]->nullable = $query[$i]->IS_NULLABLE !== 'NO';
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
}
return $retVal;

View File

@ -274,12 +274,12 @@ class Connection extends BaseConnection
$retVal[$i]->name = $query[$i]->name;
$retVal[$i]->type = $query[$i]->type;
$retVal[$i]->max_length = null;
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
$retVal[$i]->default = $query[$i]->dflt_value;
// "pk" (either zero for columns that are not part of the primary key,
// or the 1-based index of the column within the primary key).
// https://www.sqlite.org/pragma.html#pragma_table_info
$retVal[$i]->primary_key = ($query[$i]->pk === 0) ? 0 : 1;
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
}
return $retVal;

View File

@ -21,13 +21,16 @@ use Stringable;
*/
class TestLogger extends Logger
{
/**
* @var list<array{level: mixed, message: string, file: string|null}>
*/
protected static $op_logs = [];
/**
* The log method is overridden so that we can store log history during
* the tests to allow us to check ->assertLogged() methods.
*
* @param string $level
* @param mixed $level
* @param string $message
*/
public function log($level, string|Stringable $message, array $context = []): void
@ -95,6 +98,8 @@ class TestLogger extends Logger
*
* @param string $file
*
* @return string
*
* @deprecated No longer needed as underlying protected method is also deprecated.
*/
public function cleanup($file)

View File

@ -955,30 +955,30 @@ final class ForgeTest extends CIUnitTestCase
0 => [
'name' => 'id',
'type' => 'integer',
'max_length' => '32',
'nullable' => false,
'default' => "nextval('db_forge_test_fields_id_seq'::regclass)",
'max_length' => '32',
],
1 => [
'name' => 'username',
'type' => 'character varying',
'max_length' => '255',
'nullable' => false,
'default' => null,
'max_length' => '255',
],
2 => [
'name' => 'name',
'type' => 'character varying',
'max_length' => '255',
'nullable' => true,
'default' => null,
'max_length' => '255',
],
3 => [
'name' => 'active',
'type' => 'integer',
'max_length' => '32',
'nullable' => false,
'default' => '0',
'max_length' => '32',
],
];
} elseif ($this->db->DBDriver === 'SQLite3') {
@ -987,33 +987,33 @@ final class ForgeTest extends CIUnitTestCase
'name' => 'id',
'type' => 'INTEGER',
'max_length' => null,
'nullable' => true,
'default' => null,
'primary_key' => 1,
'nullable' => true,
],
1 => [
'name' => 'username',
'type' => 'VARCHAR',
'max_length' => null,
'nullable' => false,
'default' => null,
'primary_key' => 0,
'nullable' => false,
],
2 => [
'name' => 'name',
'type' => 'VARCHAR',
'max_length' => null,
'nullable' => true,
'default' => null,
'primary_key' => 0,
'nullable' => true,
],
3 => [
'name' => 'active',
'type' => 'INTEGER',
'max_length' => null,
'nullable' => false,
'default' => '0',
'primary_key' => 0,
'nullable' => false,
],
];
} elseif ($this->db->DBDriver === 'SQLSRV') {
@ -1021,30 +1021,30 @@ final class ForgeTest extends CIUnitTestCase
0 => [
'name' => 'id',
'type' => 'int',
'default' => null,
'max_length' => 10,
'nullable' => false,
'default' => null,
],
1 => [
'name' => 'username',
'type' => 'varchar',
'default' => null,
'max_length' => 255,
'nullable' => false,
'default' => null,
],
2 => [
'name' => 'name',
'type' => 'varchar',
'default' => null,
'max_length' => 255,
'nullable' => true,
'default' => null,
],
3 => [
'name' => 'active',
'type' => 'int',
'default' => '((0))', // Why?
'max_length' => 10,
'nullable' => false,
'default' => '((0))', // Why?
],
];
} elseif ($this->db->DBDriver === 'OCI8') {
@ -1053,29 +1053,29 @@ final class ForgeTest extends CIUnitTestCase
'name' => 'id',
'type' => 'NUMBER',
'max_length' => '11',
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
'nullable' => false,
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
],
1 => [
'name' => 'username',
'type' => 'VARCHAR2',
'max_length' => '255',
'default' => null,
'nullable' => false,
'default' => null,
],
2 => [
'name' => 'name',
'type' => 'VARCHAR2',
'max_length' => '255',
'default' => null,
'nullable' => true,
'default' => null,
],
3 => [
'name' => 'active',
'type' => 'NUMBER',
'max_length' => '11',
'default' => '0 ', // Why?
'nullable' => false,
'default' => '0 ', // Why?
],
];

View File

@ -50,57 +50,57 @@ final class GetFieldDataTest extends AbstractGetFieldDataTest
'name' => 'id',
'type' => 'NUMBER',
'max_length' => '11',
'nullable' => false,
'default' => $idDefault, // The default value is not defined.
// 'primary_key' => 1,
'nullable' => false,
],
(object) [
'name' => 'text_not_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => true,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'int_default_0',
'type' => 'NUMBER',
'max_length' => '11',
'nullable' => false,
'default' => '0 ', // int 0
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => true,
'default' => 'NULL ', // NULL value
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'text_default_text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => "'null' ", // string "null"
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_abc',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => "'abc' ", // string "abc"
// 'primary_key' => 0,
'nullable' => false,
],
]), true);
$names = array_column($expected, 'name');

View File

@ -94,23 +94,29 @@ Usage example:
.. literalinclude:: metadata/006.php
If you have run a query already you can use the result object instead of
supplying the table name:
.. literalinclude:: metadata/007.php
The following data is available from this function if supported by your
database:
- ``name`` - column name
- ``type`` - the type of the column
- ``max_length`` - maximum length of the column
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)
- ``nullable`` - boolean ``true`` if the column is nullable, otherwise boolean ``false``
- ``default`` - the default value
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)
.. note:: Since v4.4.0, SQLSRV supported ``nullable``.
$query->getFieldData()
----------------------
If you have run a query already you can use the result object instead of
supplying the table name:
.. literalinclude:: metadata/007.php
.. note:: The data returned is different from the data from ``$db->getFieldData()``.
If you cannot get the data you need, use ``$db->getFieldData()``.
List the Indexes in a Table
===========================