File tree Expand file tree Collapse file tree 6 files changed +85
-4
lines changed
tests/Console/ModelsCommand/Relations Expand file tree Collapse file tree 6 files changed +85
-4
lines changed Original file line number Diff line number Diff line change @@ -753,9 +753,14 @@ public function getPropertiesFromMethods($model)
753
753
get_class ($ relationObj ->getRelated ())
754
754
);
755
755
756
+ $ relationReturnType = $ this ->getRelationReturnTypes ()[$ relation ] ?? false ;
757
+
756
758
if (
757
- strpos (get_class ($ relationObj ), 'Many ' ) !== false ||
758
- ($ this ->getRelationReturnTypes ()[$ relation ] ?? '' ) === 'many '
759
+ $ relationReturnType === 'many ' ||
760
+ (
761
+ !$ relationReturnType &&
762
+ strpos (get_class ($ relationObj ), 'Many ' ) !== false
763
+ )
759
764
) {
760
765
//Collection or array of models (because Collection is Arrayable)
761
766
$ relatedClass = '\\' . get_class ($ relationObj ->getRelated ());
@@ -782,8 +787,11 @@ public function getPropertiesFromMethods($model)
782
787
);
783
788
}
784
789
} elseif (
785
- $ relation === 'morphTo ' ||
786
- ($ this ->getRelationReturnTypes ()[$ relation ] ?? '' ) === 'morphTo '
790
+ $ relationReturnType === 'morphTo ' ||
791
+ (
792
+ !$ relationReturnType &&
793
+ $ relation === 'morphTo '
794
+ )
787
795
) {
788
796
// Model isn't specified because relation is polymorphic
789
797
$ this ->setProperty (
Original file line number Diff line number Diff line change @@ -107,4 +107,9 @@ public function relationSampleToAnyMorphedRelationType()
107
107
{
108
108
return $ this ->testToAnyMorphedRelation (Simple::class);
109
109
}
110
+
111
+ public function relationSampleToBadlyNamedNotManyRelation ()
112
+ {
113
+ return $ this ->testToBadlyNamedNotManyRelation (Simple::class);
114
+ }
110
115
}
Original file line number Diff line number Diff line change 8
8
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \AbstractModelsCommand ;
9
9
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToAnyMorphedRelationType ;
10
10
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToAnyRelationType ;
11
+ use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToBadlyNamedNotManyRelationType ;
11
12
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToManyRelationType ;
12
13
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToOneRelationType ;
13
14
use Illuminate \Support \Facades \Config ;
@@ -23,11 +24,13 @@ protected function setUp(): void
23
24
'testToManyRelation ' => SampleToManyRelationType::class,
24
25
'testToAnyRelation ' => SampleToAnyRelationType::class,
25
26
'testToAnyMorphedRelation ' => SampleToAnyMorphedRelationType::class,
27
+ 'testToBadlyNamedNotManyRelation ' => SampleToBadlyNamedNotManyRelationType::class,
26
28
]);
27
29
28
30
Config::set ('ide-helper.additional_relation_return_types ' , [
29
31
'testToAnyRelation ' => 'many ' ,
30
32
'testToAnyMorphedRelation ' => 'morphTo ' ,
33
+ 'testToBadlyNamedNotManyRelation ' => 'one ' ,
31
34
]);
32
35
}
33
36
Original file line number Diff line number Diff line change 6
6
7
7
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToAnyMorphedRelationType ;
8
8
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToAnyRelationType ;
9
+ use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToBadlyNamedNotManyRelationType ;
9
10
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToManyRelationType ;
10
11
use Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types \SampleToOneRelationType ;
11
12
@@ -34,4 +35,10 @@ public function testToAnyMorphedRelation($related)
34
35
$ instance = $ this ->newRelatedInstance ($ related );
35
36
return new SampleToAnyMorphedRelationType ($ instance ->newQuery (), $ this );
36
37
}
38
+
39
+ public function testToBadlyNamedNotManyRelation ($ related )
40
+ {
41
+ $ instance = $ this ->newRelatedInstance ($ related );
42
+ return new SampleToBadlyNamedNotManyRelationType ($ instance ->newQuery (), $ this );
43
+ }
37
44
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Barryvdh \LaravelIdeHelper \Tests \Console \ModelsCommand \Relations \Types ;
6
+
7
+ use Illuminate \Database \Eloquent \Collection ;
8
+ use Illuminate \Database \Eloquent \Model ;
9
+ use Illuminate \Database \Eloquent \Relations \Concerns \SupportsDefaultModels ;
10
+ use Illuminate \Database \Eloquent \Relations \Relation ;
11
+
12
+ /**
13
+ * Sample for custom relation
14
+ *
15
+ * the relation is a big fake and only for testing of the docblock generation
16
+ *
17
+ * @package Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations
18
+ */
19
+ class SampleToBadlyNamedNotManyRelationType extends Relation
20
+ {
21
+ use SupportsDefaultModels;
22
+
23
+ public function addConstraints ()
24
+ {
25
+ // Fake
26
+ }
27
+
28
+ public function addEagerConstraints (array $ models )
29
+ {
30
+ // Fake
31
+ }
32
+
33
+ public function initRelation (array $ models , $ relation )
34
+ {
35
+ // Fake
36
+ }
37
+
38
+ public function match (array $ models , Collection $ results , $ relation )
39
+ {
40
+ // Fake
41
+ }
42
+
43
+ public function getResults ()
44
+ {
45
+ // Fake
46
+ }
47
+
48
+ protected function newRelatedInstanceFor (Model $ parent )
49
+ {
50
+ // Fake
51
+ }
52
+ }
Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ public function nullableMixedWithForeignKeyConstraint(): BelongsTo
159
159
* @property-read Model|\Eloquent $relationSampleToAnyMorphedRelationType
160
160
* @property-read \Illuminate\Database\Eloquent\Collection<int, Simple> $relationSampleToAnyRelationType
161
161
* @property-read int|null $relation_sample_to_any_relation_type_count
162
+ * @property-read Simple $relationSampleToBadlyNamedNotManyRelation
162
163
* @property-read Simple $relationSampleToManyRelationType
163
164
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
164
165
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
@@ -257,4 +258,9 @@ public function relationSampleToAnyMorphedRelationType()
257
258
{
258
259
return $ this ->testToAnyMorphedRelation (Simple::class);
259
260
}
261
+
262
+ public function relationSampleToBadlyNamedNotManyRelation ()
263
+ {
264
+ return $ this ->testToBadlyNamedNotManyRelation (Simple::class);
265
+ }
260
266
}
You can’t perform that action at this time.
0 commit comments