Skip to content

Commit dc509e9

Browse files
committed
chore: format
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent c57e3db commit dc509e9

File tree

6 files changed

+9
-109
lines changed

6 files changed

+9
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Generate PHP code from Rust using a fluent API 🐘 🦀
2424
- [x] Code generation for modifiers
2525
- [x] Code generation for visibility
2626
- [x] Code generation for function/method bodies
27-
- [ ] Code generation for interfaces
27+
- [x] Code generation for interfaces
2828
- [ ] Code generation for enums
2929
- [ ] Code generation for traits
3030
- [ ] Code generation for trait use statements

examples/complete.php

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace Foo;
6-
7-
use Foo\Bar\Baz as Qux;
8-
use Throwable;
9-
use DateTime;
10-
use DateTimeImmutable;
11-
12-
use function strlen;
13-
use function array_map;
14-
use function array_filter;
15-
16-
use const Foo\HELLO;
17-
use const Foo\HEY;
18-
19-
20-
const A = "Hello World!";
21-
const B = null;
22-
const C = 1;
23-
const D = false;
24-
const E = null;
25-
const F = 213.412;
26-
const G = [1, 25];
5+
namespace App;
276

287
/**
29-
* This is a simple hello function.
30-
*
31-
* @param non-empty-string $firstname
8+
* Format a string with the given arguments using sprintf.
329
*
33-
* @return string
10+
* @param non-empty-string $template
3411
*
3512
* @pure
3613
*/
37-
#[Qux(foo: 1, bar: 2)]
38-
function hello(
39-
#[Validation\NotBlank, Validation\Length(min: 2, max: 10)]
40-
string $firstname,
41-
string $lastname = Qux::Foo,
42-
): string {
43-
return 'Hello ' . $firstname . ' ' . $lastname . '!';
44-
}
45-
46-
function nothing(): void {
47-
// empty body
48-
}
49-
5014
function format(
5115
string $template,
5216
int|float|string|null ...$args,
@@ -57,65 +21,3 @@ function format(
5721
));
5822
}
5923

60-
/**
61-
* This is an example class.
62-
*
63-
* @immutable
64-
*/
65-
abstract class Example
66-
{
67-
final const A = "Hello World!";
68-
69-
protected const B = null;
70-
71-
private const C = 1;
72-
73-
public const D = false;
74-
75-
private string $foo;
76-
77-
protected string $bar;
78-
79-
public string|int $baz = "Hello World!";
80-
81-
/**
82-
* This is a simple hello function.
83-
*
84-
* @param non-empty-string $firstname
85-
*
86-
* @return string
87-
*
88-
* @pure
89-
*/
90-
#[Qux(foo: 1, bar: 2), Qux(foo: 1, bar: 2)]
91-
function hello(
92-
string $firstname,
93-
string $lastname = Qux::Foo,
94-
): string {
95-
return 'Hello ' . $firstname . ' ' . $lastname . '!';
96-
}
97-
98-
/**
99-
* This is a simple x function.
100-
*
101-
* @pure
102-
*/
103-
#[Foo(foo: 1, bar: 2), Bar(foo: 1, bar: 2)]
104-
#[Baz, Qux]
105-
public function x(): mixed {
106-
return 'Hello!';
107-
}
108-
109-
/**
110-
* This is a simple poop function.
111-
*/
112-
public abstract function poop(): void;
113-
114-
/**
115-
* This is a simple echo function.
116-
*/
117-
public final function helloWorld(): void {
118-
echo 'Hello World!';
119-
}
120-
}
121-

examples/complete.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ fn main() {
6666
.function(Function::new("nothing").returns(DataType::Void))
6767
.function(
6868
Function::new("format")
69-
.parameter(
70-
Parameter::new("template")
71-
.typed(DataType::String)
72-
)
69+
.parameter(Parameter::new("template").typed(DataType::String))
7370
.parameter(
7471
Parameter::new("args")
7572
.variadic()

examples/simple.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ function format(
2020
array_filter($args, static fn ($arg) => $arg !== null)
2121
));
2222
}
23+

src/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{comment::Document, attribute::AttributeGroup, Generator, Indentation, method::Method};
1+
use crate::{attribute::AttributeGroup, comment::Document, method::Method, Generator, Indentation};
22

33
#[derive(Debug)]
44
pub struct Interface {
@@ -80,4 +80,4 @@ impl Generator for Interface {
8080

8181
code
8282
}
83-
}
83+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub mod constant;
66
pub mod data_type;
77
pub mod file;
88
pub mod function;
9+
pub mod interface;
910
pub mod literal;
1011
pub mod method;
1112
pub mod modifiers;
1213
pub mod parameter;
1314
pub mod property;
14-
pub mod interface;
1515

1616
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
1717
pub enum Indentation {

0 commit comments

Comments
 (0)