Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c3fe4aa0
Commit
c3fe4aa0
authored
May 06, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`@inheritdoc` from interfaces and params
parent
39a2e1ef
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
15 deletions
+88
-15
BaseDoc.php
extensions/apidoc/models/BaseDoc.php
+21
-1
Context.php
extensions/apidoc/models/Context.php
+66
-14
Object.php
framework/base/Object.php
+1
-0
No files found.
extensions/apidoc/models/BaseDoc.php
View file @
c3fe4aa0
...
...
@@ -42,6 +42,26 @@ class BaseDoc extends Object
*/
public
$tags
=
[];
public
function
hasTag
(
$name
)
{
foreach
(
$this
->
tags
as
$tag
)
{
if
(
strtolower
(
$tag
->
getName
())
==
$name
)
{
return
true
;
}
}
return
false
;
}
public
function
removeTag
(
$name
)
{
foreach
(
$this
->
tags
as
$i
=>
$tag
)
{
if
(
strtolower
(
$tag
->
getName
())
==
$name
)
{
unset
(
$this
->
tags
[
$i
]);
}
}
}
/**
* @param \phpDocumentor\Reflection\BaseReflector $reflector
* @param Context $context
...
...
@@ -70,7 +90,7 @@ class BaseDoc extends Object
'message'
=>
"No short description for "
.
substr
(
StringHelper
::
basename
(
get_class
(
$this
)),
0
,
-
3
)
.
" '
{
$this
->
name
}
'"
,
];
}
$this
->
description
=
$docblock
->
getLongDescription
();
$this
->
description
=
$docblock
->
getLongDescription
()
->
getContents
()
;
$this
->
phpDocContext
=
$docblock
->
getContext
();
...
...
extensions/apidoc/models/Context.php
View file @
c3fe4aa0
...
...
@@ -164,11 +164,33 @@ class Context extends Component
{
// TODO also for properties?
foreach
(
$class
->
methods
as
$m
)
{
$inheritedMethod
=
$this
->
inheritMethodRecursive
(
$m
,
$class
);
foreach
([
'shortDescription'
,
'description'
,
'params'
,
'return'
,
'returnType'
,
'returnTypes'
,
'exceptions'
]
as
$property
)
{
if
(
empty
(
$m
->
$property
))
{
$m
->
$property
=
$inheritedMethod
->
$property
;
if
(
$m
->
hasTag
(
'inheritdoc'
))
{
$inheritedMethod
=
$this
->
inheritMethodRecursive
(
$m
,
$class
);
foreach
([
'shortDescription'
,
'description'
,
'return'
,
'returnType'
,
'returnTypes'
,
'exceptions'
]
as
$property
)
{
if
(
empty
(
$m
->
$property
)
||
is_string
(
$m
->
$property
)
&&
trim
(
$m
->
$property
)
===
''
)
{
$m
->
$property
=
$inheritedMethod
->
$property
;
}
}
foreach
(
$m
->
params
as
$i
=>
$param
)
{
if
(
!
isset
(
$inheritedMethod
->
params
[
$i
]))
{
$this
->
errors
[]
=
[
'line'
=>
$m
->
startLine
,
'file'
=>
$class
->
sourceFile
,
'message'
=>
"Method param
$i
does not exist in parent method, @inheritdoc not possible in
{
$m
->
name
}
in
{
$class
->
name
}
."
,
];
continue
;
}
if
(
empty
(
$param
->
description
)
||
trim
(
$param
->
description
)
===
''
)
{
$param
->
description
=
$inheritedMethod
->
params
[
$i
]
->
description
;
}
if
(
empty
(
$param
->
type
)
||
trim
(
$param
->
type
)
===
''
)
{
$param
->
type
=
$inheritedMethod
->
params
[
$i
]
->
type
;
}
if
(
empty
(
$param
->
types
)
||
trim
(
$param
->
types
)
===
''
)
{
$param
->
types
=
$inheritedMethod
->
params
[
$i
]
->
types
;
}
}
$m
->
removeTag
(
'inheritdoc'
);
}
}
}
...
...
@@ -179,20 +201,50 @@ class Context extends Component
*/
private
function
inheritMethodRecursive
(
$method
,
$class
)
{
if
(
!
isset
(
$this
->
classes
[
$class
->
parentClass
]))
{
return
$method
;
}
$parent
=
$this
->
classes
[
$class
->
parentClass
];
foreach
(
$method
->
tags
as
$tag
)
{
if
(
strtolower
(
$tag
->
getName
())
==
'inheritdoc'
)
{
if
(
isset
(
$parent
->
methods
[
$method
->
name
]))
{
$method
=
$parent
->
methods
[
$method
->
name
];
$inheritanceCandidates
=
array_merge
(
$this
->
getParents
(
$class
),
$this
->
getInterfaces
(
$class
)
);
$methods
=
[];
foreach
(
$inheritanceCandidates
as
$candidate
)
{
if
(
isset
(
$candidate
->
methods
[
$method
->
name
]))
{
$cmethod
=
$candidate
->
methods
[
$method
->
name
];
if
(
$cmethod
->
hasTag
(
'inheritdoc'
))
{
$this
->
inheritDocs
(
$candidate
);
}
$methods
[]
=
$cmethod
;
}
}
return
$this
->
inheritMethodRecursive
(
$method
,
$parent
);
return
reset
(
$methods
);
}
/**
* @param ClassDoc $class
* @return array
*/
private
function
getParents
(
$class
)
{
if
(
$class
->
parentClass
===
null
||
!
isset
(
$this
->
classes
[
$class
->
parentClass
]))
{
return
[];
}
return
array_merge
([
$this
->
classes
[
$class
->
parentClass
]],
$this
->
getParents
(
$this
->
classes
[
$class
->
parentClass
]));
}
/**
* @param ClassDoc $class
* @return array
*/
private
function
getInterfaces
(
$class
)
{
$interfaces
=
[];
foreach
(
$class
->
interfaces
as
$interface
)
{
if
(
isset
(
$this
->
interfaces
[
$interface
]))
{
$interfaces
[]
=
$this
->
interfaces
[
$interface
];
}
}
return
$
method
;
return
$
interfaces
;
}
/**
...
...
framework/base/Object.php
View file @
c3fe4aa0
...
...
@@ -77,6 +77,7 @@ use Yii;
class
Object
{
/**
* Returns the fully qualified name of this class.
* @return string the fully qualified name of this class.
*/
public
static
function
className
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment