From ee38f72351b9d3eaa4e4f7ef0630762ba746cfd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 16 Dec 2025 09:54:31 +0100 Subject: [PATCH] Fix example syntax and add stub file to make IDE happy --- db-transaction/application/0-linear-code.php | 2 +- db-transaction/application/1a-raii-no-helpers.php | 2 +- .../application/1b-raii-with-scope-block.php | 4 ++-- .../application/1c-raii-with-scope-declaration.php | 2 +- db-transaction/application/2-context-manager.php | 2 +- .../application/3a-ioc-current-closure.php | 2 +- db-transaction/application/3b-ioc-auto-capture.php | 2 +- .../application/1b-raii-with-scope-block.php | 4 ++-- .../application/3a-ioc-current-closure.php | 2 +- .../application/3b-ioc-auto-capture.php | 2 +- file-handle/application/3a-ioc-current-closure.php | 2 +- file-handle/application/3b-ioc-auto-capture.php | 2 +- file-object/application/2-context-manager.php | 14 +++++++------- file-object/application/3a-ioc-current-closure.php | 2 +- file-object/application/3b-ioc-auto-capture.php | 2 +- stub.php | 8 ++++++++ 16 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 stub.php diff --git a/db-transaction/application/0-linear-code.php b/db-transaction/application/0-linear-code.php index 5ca80a9..b6b7dcf 100644 --- a/db-transaction/application/0-linear-code.php +++ b/db-transaction/application/0-linear-code.php @@ -12,7 +12,7 @@ function example(DB $db) $db->beginTransaction(); // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo'=>$foo,]); - something_with($bar); + do_something_with($bar); // ... $db->commitTransaction(); } diff --git a/db-transaction/application/1a-raii-no-helpers.php b/db-transaction/application/1a-raii-no-helpers.php index 1ec31f7..413db83 100644 --- a/db-transaction/application/1a-raii-no-helpers.php +++ b/db-transaction/application/1a-raii-no-helpers.php @@ -16,7 +16,7 @@ function example(DB $db) $transaction = $db->newTransaction(); // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo' => $foo,]); - something_with($bar); + do_something_with($bar); // ... $transaction->commit(); } diff --git a/db-transaction/application/1b-raii-with-scope-block.php b/db-transaction/application/1b-raii-with-scope-block.php index d9c00c1..9dbac1d 100644 --- a/db-transaction/application/1b-raii-with-scope-block.php +++ b/db-transaction/application/1b-raii-with-scope-block.php @@ -8,10 +8,10 @@ function example(DB $db) $foo = various_unrelated_code(); $bar = 'some important value'; - use ($transaction = $db->newTransaction()) try { + let ($transaction = $db->newTransaction()) try { // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo'=>$foo,]); - something_with($bar); + do_something_with($bar); // ... $transaction->commit(); } diff --git a/db-transaction/application/1c-raii-with-scope-declaration.php b/db-transaction/application/1c-raii-with-scope-declaration.php index 02dd74f..7b293f9 100644 --- a/db-transaction/application/1c-raii-with-scope-declaration.php +++ b/db-transaction/application/1c-raii-with-scope-declaration.php @@ -14,7 +14,7 @@ function example(DB $db) let $transaction = $db->newTransaction(); // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo'=>$foo,]); - something_with($bar); + do_something_with($bar); // ... $transaction->commit(); } diff --git a/db-transaction/application/2-context-manager.php b/db-transaction/application/2-context-manager.php index 61f3fc6..53c3663 100644 --- a/db-transaction/application/2-context-manager.php +++ b/db-transaction/application/2-context-manager.php @@ -12,7 +12,7 @@ function example(DB $db) using ($db->transactionScope()) { // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo'=>$foo,]); - something_with($bar); + do_something_with($bar); // ... } } diff --git a/db-transaction/application/3a-ioc-current-closure.php b/db-transaction/application/3a-ioc-current-closure.php index 0bd04e0..436554f 100644 --- a/db-transaction/application/3a-ioc-current-closure.php +++ b/db-transaction/application/3a-ioc-current-closure.php @@ -12,7 +12,7 @@ function example(DB $db) $db->doInTransaction(function(DB $db) use($foo, $bar) { // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo' => $foo,]); - something_with($bar); + do_something_with($bar); // ... }); } catch (SomeSpecificException $e) { diff --git a/db-transaction/application/3b-ioc-auto-capture.php b/db-transaction/application/3b-ioc-auto-capture.php index 8b19d2b..3b006a2 100644 --- a/db-transaction/application/3b-ioc-auto-capture.php +++ b/db-transaction/application/3b-ioc-auto-capture.php @@ -12,7 +12,7 @@ function example(DB $db) $db->doInTransaction(fn(DB $db) { // ... $db->execute('INSERT INTO Something (Foo) Values (:Foo)', ['Foo' => $foo,]); - something_with($bar); + do_something_with($bar); // ... }); } catch (SomeSpecificException $e) { diff --git a/file-handle-unguarded/application/1b-raii-with-scope-block.php b/file-handle-unguarded/application/1b-raii-with-scope-block.php index 3636494..99d4866 100644 --- a/file-handle-unguarded/application/1b-raii-with-scope-block.php +++ b/file-handle-unguarded/application/1b-raii-with-scope-block.php @@ -8,7 +8,7 @@ function example() { $someThing = some_unrelated_code(); - let ($fh = fopen('file.txt', 'w') { + let ($fh = fopen('file.txt', 'w')) { if ($fh === false) { log('Failed to open file.'); } @@ -33,7 +33,7 @@ function example_extra_concise() { $someThing = some_unrelated_code(); - let ($fh = fopen('file.txt', 'w') if ($fh === false) { + let ($fh = fopen('file.txt', 'w')) if ($fh === false) { log('Failed to open file.'); } else try { diff --git a/file-handle-unguarded/application/3a-ioc-current-closure.php b/file-handle-unguarded/application/3a-ioc-current-closure.php index 3d12f4c..61c90d7 100644 --- a/file-handle-unguarded/application/3a-ioc-current-closure.php +++ b/file-handle-unguarded/application/3a-ioc-current-closure.php @@ -19,7 +19,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/file-handle-unguarded/application/3b-ioc-auto-capture.php b/file-handle-unguarded/application/3b-ioc-auto-capture.php index 8d6731b..3779e95 100644 --- a/file-handle-unguarded/application/3b-ioc-auto-capture.php +++ b/file-handle-unguarded/application/3b-ioc-auto-capture.php @@ -19,7 +19,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/file-handle/application/3a-ioc-current-closure.php b/file-handle/application/3a-ioc-current-closure.php index ba18fa0..5f30bc6 100644 --- a/file-handle/application/3a-ioc-current-closure.php +++ b/file-handle/application/3a-ioc-current-closure.php @@ -17,7 +17,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/file-handle/application/3b-ioc-auto-capture.php b/file-handle/application/3b-ioc-auto-capture.php index d67a0b1..a3517ec 100644 --- a/file-handle/application/3b-ioc-auto-capture.php +++ b/file-handle/application/3b-ioc-auto-capture.php @@ -17,7 +17,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/file-object/application/2-context-manager.php b/file-object/application/2-context-manager.php index a35547f..ca338dd 100644 --- a/file-object/application/2-context-manager.php +++ b/file-object/application/2-context-manager.php @@ -9,14 +9,14 @@ function example() $someThing = some_unrelated_code(); try using (file_for_write('file.txt') as $fh) { - foreach ($someThing as $value) { - fwrite($fh, serialize($value)); + foreach ($someThing as $value) { + fwrite($fh, serialize($value)); + } + } catch (\FileOpeningException $e) { + log('Failed to open file.'); + } catch (\Exception $e) { + log('Failed processing the file in some way.'); } -} catch (\FileOpeningException $e) { - log('Failed to open file.'); -} catch (\Exception $e) { - log('Failed processing the file in some way.'); -} various_unrelated_code(); } diff --git a/file-object/application/3a-ioc-current-closure.php b/file-object/application/3a-ioc-current-closure.php index ba18fa0..5f30bc6 100644 --- a/file-object/application/3a-ioc-current-closure.php +++ b/file-object/application/3a-ioc-current-closure.php @@ -17,7 +17,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/file-object/application/3b-ioc-auto-capture.php b/file-object/application/3b-ioc-auto-capture.php index d67a0b1..a3517ec 100644 --- a/file-object/application/3b-ioc-auto-capture.php +++ b/file-object/application/3b-ioc-auto-capture.php @@ -17,7 +17,7 @@ function example() } catch (\Exception $e) { log('Failed processing the file in some way.'); } - } + }); various_unrelated_code(); } diff --git a/stub.php b/stub.php new file mode 100644 index 0000000..e25fe2b --- /dev/null +++ b/stub.php @@ -0,0 +1,8 @@ +