Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thecodingmachine/safe
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.1
Choose a base ref
...
head repository: thecodingmachine/safe
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.2
Choose a head ref
  • 4 commits
  • 87 files changed
  • 1 contributor

Commits on Feb 18, 2025

  1. more docs

    shish committed Feb 18, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    323f249 View commit details

Commits on Feb 19, 2025

  1. Remove more redundant overrides

    These overrides have no effect on the generated code
    shish committed Feb 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a775bd3 View commit details
  2. Retain specific int details in docblocks

    We're already using PHPStan's more-specific-types _some_ of the time - let's do it consistently?
    
    See also: thecodingmachine/phpstan-safe-rule#52
    shish committed Feb 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    efc63c4 View commit details
  3. fix readme badge

    shish committed Feb 19, 2025
    Copy the full SHA
    22ffad3 View commit details
Showing with 301 additions and 269 deletions.
  1. +32 −1 CONTRIBUTING.md
  2. +1 −1 README.md
  3. +2 −2 generated/8.1/dir.php
  4. +1 −1 generated/8.1/errorfunc.php
  5. +13 −13 generated/8.1/filesystem.php
  6. +6 −6 generated/8.1/ftp.php
  7. +1 −1 generated/8.1/iconv.php
  8. +2 −2 generated/8.1/image.php
  9. +1 −1 generated/8.1/json.php
  10. +4 −4 generated/8.1/mbstring.php
  11. +1 −1 generated/8.1/network.php
  12. +1 −1 generated/8.1/oci8.php
  13. +2 −2 generated/8.1/openssl.php
  14. +3 −3 generated/8.1/pcre.php
  15. +3 −3 generated/8.1/posix.php
  16. +1 −1 generated/8.1/stream.php
  17. +2 −2 generated/8.1/zlib.php
  18. +2 −2 generated/8.2/dir.php
  19. +1 −1 generated/8.2/errorfunc.php
  20. +13 −13 generated/8.2/filesystem.php
  21. +2 −2 generated/8.2/fpm.php
  22. +6 −6 generated/8.2/ftp.php
  23. +1 −1 generated/8.2/iconv.php
  24. +2 −2 generated/8.2/image.php
  25. +1 −1 generated/8.2/json.php
  26. +4 −4 generated/8.2/mbstring.php
  27. +1 −1 generated/8.2/network.php
  28. +1 −1 generated/8.2/oci8.php
  29. +2 −2 generated/8.2/openssl.php
  30. +3 −3 generated/8.2/pcre.php
  31. +3 −3 generated/8.2/posix.php
  32. +1 −1 generated/8.2/stream.php
  33. +2 −2 generated/8.2/zlib.php
  34. +2 −2 generated/8.3/dir.php
  35. +1 −1 generated/8.3/errorfunc.php
  36. +13 −13 generated/8.3/filesystem.php
  37. +2 −2 generated/8.3/fpm.php
  38. +6 −6 generated/8.3/ftp.php
  39. +1 −1 generated/8.3/iconv.php
  40. +2 −2 generated/8.3/image.php
  41. +1 −1 generated/8.3/json.php
  42. +4 −4 generated/8.3/mbstring.php
  43. +1 −1 generated/8.3/network.php
  44. +1 −1 generated/8.3/oci8.php
  45. +2 −2 generated/8.3/openssl.php
  46. +3 −3 generated/8.3/pcre.php
  47. +3 −3 generated/8.3/posix.php
  48. +1 −1 generated/8.3/stream.php
  49. +2 −2 generated/8.3/zlib.php
  50. +2 −2 generated/8.4/dir.php
  51. +1 −1 generated/8.4/errorfunc.php
  52. +13 −13 generated/8.4/filesystem.php
  53. +2 −2 generated/8.4/fpm.php
  54. +7 −7 generated/8.4/ftp.php
  55. +1 −1 generated/8.4/ibmDb2.php
  56. +1 −1 generated/8.4/iconv.php
  57. +2 −2 generated/8.4/image.php
  58. +1 −1 generated/8.4/json.php
  59. +4 −4 generated/8.4/mbstring.php
  60. +1 −1 generated/8.4/network.php
  61. +1 −1 generated/8.4/oci8.php
  62. +2 −2 generated/8.4/openssl.php
  63. +3 −3 generated/8.4/pcre.php
  64. +3 −3 generated/8.4/posix.php
  65. +1 −1 generated/8.4/stream.php
  66. +2 −2 generated/8.4/zlib.php
  67. +2 −2 generated/8.5/dir.php
  68. +1 −1 generated/8.5/errorfunc.php
  69. +13 −13 generated/8.5/filesystem.php
  70. +2 −2 generated/8.5/fpm.php
  71. +7 −7 generated/8.5/ftp.php
  72. +1 −1 generated/8.5/ibmDb2.php
  73. +1 −1 generated/8.5/iconv.php
  74. +2 −2 generated/8.5/image.php
  75. +1 −1 generated/8.5/json.php
  76. +4 −4 generated/8.5/mbstring.php
  77. +1 −1 generated/8.5/network.php
  78. +1 −1 generated/8.5/oci8.php
  79. +2 −2 generated/8.5/openssl.php
  80. +3 −3 generated/8.5/pcre.php
  81. +3 −3 generated/8.5/posix.php
  82. +1 −1 generated/8.5/stream.php
  83. +2 −2 generated/8.5/zlib.php
  84. +1 −5 generator/config/CustomPhpStanFunctionMap.php
  85. +16 −25 generator/src/PhpStanFunctions/PhpStanType.php
  86. +9 −0 generator/src/XmlDocParser/Type.php
  87. +15 −10 generator/tests/PhpStanFunctions/PhpStanTypeTest.php
33 changes: 32 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -35,6 +35,29 @@ Safe-PHP code is generated automatically from the PHP doc.
`generated/` and the files in `lib/` auto-loaded; they shouldn't
need to worry about any files outside those two directories.

### Compatibility with upstream PHP

Intentional changes:
* Functions which return a special value to indicate an error should now throw an `Exception`.
* eg `file_get_contents()` returns a `string` on success, or returns `false` on error.
`\Safe\file_get_contents()` returns a `string` on success and throws an `Exception` on error.
* If the return type included that type only for errors, that type is removed from the signature.
* eg `file_get_contents()` returns `string|false`, `\Safe\file_get_contents()` returns `string`
* `proc_close()` returns the process exit code on success and -1 on error.
Both of these are `int`, so the signature remains `int`.
* If the function returned `true` on success and `false` on error, and we have
removed the `false`, then the signature gets changed from `bool` to `void` to
stop people from accidentally writing `if(function()) {...}`
* PHPDoc comments use the more specific type hints from PHPStan, eg `array<string>` rather than
`array`, or `0|1` rather than `int`

Necessary changes / side effects:
* Functions which have optional parameters without defaults (eg `cubrid_bind()` has
`$bind_value_type`) are turned into functions with nullable parameters which
default to `null`.
* PHP's internal error marker (The thing retrieved by `error_get_last()`) will be cleared
each time a Safe function is called.

## Minimum Supported PHP Version

See https://www.php.net/supported-versions.php
@@ -97,7 +120,7 @@ $ php ./safe.php generate

### Detecting new cases

`generator/src/XmlDocParser/DocPage.php` uses a list of regexes to scan the
`generator/config/detectErrorType.php` uses a list of regexes to scan the
documentation looking for functions which return `false` (or `null`) on error.
If you want to add support for more functions to Safe-PHP, the easiest way is
to add more regexes here.
@@ -106,6 +129,14 @@ If you detect more cases where `false` is an exception, then you should
probably also edit `Method.php::stripReturnFalseText()` to remove the
"returns false on error" text from the documentation.

### Deprecating old cases

If the unsafe-function-detector has made a false-positive (ie, it has detected
a function returns `false` on error, when actually `false` is fine), then we
don't want to completely remove the function because that would break backwards
compatibility, but we can hide the function to avoid it being suggested to
new users.

### Special cases

In some cases, automatic generation is too difficult to execute and the function has to be written manually.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Latest Version](https://poser.pugx.org/thecodingmachine/safe/v/stable.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![Total Downloads](https://poser.pugx.org/thecodingmachine/safe/downloads.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![License](https://poser.pugx.org/thecodingmachine/safe/license.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![Continuous Integration](https://github.com/thecodingmachine/safe/workflows/Continuous%20Integration/badge.svg)](https://github.com/thecodingmachine/safe/actions)
[![Tests](https://github.com/thecodingmachine/safe/workflows/Tests/badge.svg)](https://github.com/thecodingmachine/safe/actions)
[![codecov](https://codecov.io/gh/thecodingmachine/safe/branch/master/graph/badge.svg)](https://codecov.io/gh/thecodingmachine/safe)

Safe PHP
4 changes: 2 additions & 2 deletions generated/8.1/dir.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated/8.1/errorfunc.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions generated/8.1/filesystem.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions generated/8.1/ftp.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated/8.1/iconv.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/8.1/image.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated/8.1/json.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/8.1/mbstring.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated/8.1/network.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generated/8.1/oci8.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/8.1/openssl.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions generated/8.1/pcre.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading