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
f8701625
Commit
f8701625
authored
Aug 28, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed indentation of PhpDocController and sort properties alphabetically
parent
1c9b9681
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
60 deletions
+63
-60
PhpDocController.php
build/controllers/PhpDocController.php
+63
-60
No files found.
build/controllers/PhpDocController.php
View file @
f8701625
...
@@ -54,21 +54,21 @@ class PhpDocController extends Controller
...
@@ -54,21 +54,21 @@ class PhpDocController extends Controller
$files
=
FileHelper
::
findFiles
(
$root
,
$options
);
$files
=
FileHelper
::
findFiles
(
$root
,
$options
);
$nFilesTotal
=
0
;
$nFilesTotal
=
0
;
$nFilesUpdated
=
0
;
$nFilesUpdated
=
0
;
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
$result
=
$this
->
generateClassPropertyDocs
(
$file
);
$result
=
$this
->
generateClassPropertyDocs
(
$file
);
if
(
$result
!==
false
)
{
if
(
$result
!==
false
)
{
list
(
$className
,
$phpdoc
)
=
$result
;
list
(
$className
,
$phpdoc
)
=
$result
;
if
(
$updateFiles
)
{
if
(
$updateFiles
)
{
if
(
$this
->
updateClassPropertyDocs
(
$file
,
$className
,
$phpdoc
))
{
if
(
$this
->
updateClassPropertyDocs
(
$file
,
$className
,
$phpdoc
))
{
$nFilesUpdated
++
;
$nFilesUpdated
++
;
}
}
}
elseif
(
!
empty
(
$phpdoc
))
{
}
elseif
(
!
empty
(
$phpdoc
))
{
$this
->
stdout
(
"
\n
[ "
.
$file
.
" ]
\n\n
"
,
Console
::
BOLD
);
$this
->
stdout
(
"
\n
[ "
.
$file
.
" ]
\n\n
"
,
Console
::
BOLD
);
$this
->
stdout
(
$phpdoc
);
$this
->
stdout
(
$phpdoc
);
}
}
}
}
$nFilesTotal
++
;
$nFilesTotal
++
;
}
}
$this
->
stdout
(
"
\n\n
Parsed
$nFilesTotal
files.
\n
"
);
$this
->
stdout
(
"
\n\n
Parsed
$nFilesTotal
files.
\n
"
);
$this
->
stdout
(
"Updated
$nFilesUpdated
files.
\n
"
);
$this
->
stdout
(
"Updated
$nFilesUpdated
files.
\n
"
);
...
@@ -189,12 +189,12 @@ class PhpDocController extends Controller
...
@@ -189,12 +189,12 @@ class PhpDocController extends Controller
protected
function
generateClassPropertyDocs
(
$fileName
)
protected
function
generateClassPropertyDocs
(
$fileName
)
{
{
$phpdoc
=
""
;
$phpdoc
=
""
;
$file
=
str_replace
(
"
\r
"
,
""
,
str_replace
(
"
\t
"
,
" "
,
file_get_contents
(
$fileName
,
true
)));
$file
=
str_replace
(
"
\r
"
,
""
,
str_replace
(
"
\t
"
,
" "
,
file_get_contents
(
$fileName
,
true
)));
$ns
=
$this
->
match
(
'#\nnamespace (?<name>[\w\\\\]+);\n#'
,
$file
);
$ns
=
$this
->
match
(
'#\nnamespace (?<name>[\w\\\\]+);\n#'
,
$file
);
$namespace
=
reset
(
$ns
);
$namespace
=
reset
(
$ns
);
$namespace
=
$namespace
[
'name'
];
$namespace
=
$namespace
[
'name'
];
$classes
=
$this
->
match
(
'#\n(?:abstract )?class (?<name>\w+)( |\n)(extends )?.+\{(?<content>.*)\n\}(\n|$)#'
,
$file
);
$classes
=
$this
->
match
(
'#\n(?:abstract )?class (?<name>\w+)( |\n)(extends )?.+\{(?<content>.*)\n\}(\n|$)#'
,
$file
);
if
(
count
(
$classes
)
>
1
)
{
if
(
count
(
$classes
)
>
1
)
{
$this
->
stderr
(
"[ERR] There should be only one class in a file:
$fileName
\n
"
,
Console
::
FG_RED
);
$this
->
stderr
(
"[ERR] There should be only one class in a file:
$fileName
\n
"
,
Console
::
FG_RED
);
...
@@ -213,74 +213,76 @@ class PhpDocController extends Controller
...
@@ -213,74 +213,76 @@ class PhpDocController extends Controller
}
}
$className
=
null
;
$className
=
null
;
foreach
(
$classes
as
&
$class
)
{
foreach
(
$classes
as
&
$class
)
{
$className
=
$namespace
.
'\\'
.
$class
[
'name'
];
$className
=
$namespace
.
'\\'
.
$class
[
'name'
];
$gets
=
$this
->
match
(
$gets
=
$this
->
match
(
'#\* @return (?<type>\w+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/'
.
'#\* @return (?<type>\w+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/'
.
'[\s\n]{2,}public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)#'
,
'[\s\n]{2,}public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)#'
,
$class
[
'content'
]);
$class
[
'content'
]);
$sets
=
$this
->
match
(
$sets
=
$this
->
match
(
'#\* @param (?<type>\w+) \$\w+(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/'
.
'#\* @param (?<type>\w+) \$\w+(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/'
.
'[\s\n]{2,}public function (?<kind>set)(?<name>\w+)\(\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)#'
,
'[\s\n]{2,}public function (?<kind>set)(?<name>\w+)\(\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)#'
,
$class
[
'content'
]);
$class
[
'content'
]);
$acrs
=
array_merge
(
$gets
,
$sets
);
$acrs
=
array_merge
(
$gets
,
$sets
);
//print_r($acrs); continue;
//print_r($acrs); continue;
$props
=
array
();
$props
=
array
();
foreach
(
$acrs
as
&
$acr
)
{
foreach
(
$acrs
as
&
$acr
)
{
$acr
[
'name'
]
=
lcfirst
(
$acr
[
'name'
]);
$acr
[
'name'
]
=
lcfirst
(
$acr
[
'name'
]);
$acr
[
'comment'
]
=
trim
(
preg_replace
(
'#(^|\n)\s+\*\s?#'
,
'$1 * '
,
$acr
[
'comment'
]));
$acr
[
'comment'
]
=
trim
(
preg_replace
(
'#(^|\n)\s+\*\s?#'
,
'$1 * '
,
$acr
[
'comment'
]));
$props
[
$acr
[
'name'
]][
$acr
[
'kind'
]]
=
array
(
$props
[
$acr
[
'name'
]][
$acr
[
'kind'
]]
=
array
(
'type'
=>
$acr
[
'type'
],
'type'
=>
$acr
[
'type'
],
'comment'
=>
$this
->
fixSentence
(
$acr
[
'comment'
]),
'comment'
=>
$this
->
fixSentence
(
$acr
[
'comment'
]),
);
);
}
}
ksort
(
$props
);
// foreach ($props as $propName => &$prop) // I don't like write-only props...
// foreach ($props as $propName => &$prop) // I don't like write-only props...
// if (!isset($prop['get']))
// if (!isset($prop['get']))
// unset($props[$propName]);
// unset($props[$propName]);
if
(
count
(
$props
)
>
0
)
{
if
(
count
(
$props
)
>
0
)
{
$phpdoc
.=
" *
\n
"
;
$phpdoc
.=
" *
\n
"
;
foreach
(
$props
as
$propName
=>
&
$prop
)
{
foreach
(
$props
as
$propName
=>
&
$prop
)
{
$phpdoc
.=
' * @'
;
$phpdoc
.=
' * @'
;
// if (isset($prop['get']) && isset($prop['set'])) // Few IDEs support complex syntax
// if (isset($prop['get']) && isset($prop['set'])) // Few IDEs support complex syntax
$phpdoc
.=
'property'
;
$phpdoc
.=
'property'
;
// elseif (isset($prop['get']))
// elseif (isset($prop['get']))
// $phpdoc .= 'property-read';
// $phpdoc .= 'property-read';
// elseif (isset($prop['set']))
// elseif (isset($prop['set']))
// $phpdoc .= 'property-write';
// $phpdoc .= 'property-write';
$phpdoc
.=
' '
.
$this
->
getPropParam
(
$prop
,
'type'
)
.
" $$propName "
.
$this
->
getPropParam
(
$prop
,
'comment'
)
.
"
\n
"
;
$phpdoc
.=
' '
.
$this
->
getPropParam
(
$prop
,
'type'
)
.
" $$propName "
.
$this
->
getPropParam
(
$prop
,
'comment'
)
.
"
\n
"
;
}
}
$phpdoc
.=
" *
\n
"
;
$phpdoc
.=
" *
\n
"
;
}
}
}
}
return
array
(
$className
,
$phpdoc
);
return
array
(
$className
,
$phpdoc
);
}
}
protected
function
match
(
$pattern
,
$subject
)
protected
function
match
(
$pattern
,
$subject
)
{
{
$sets
=
array
();
$sets
=
array
();
preg_match_all
(
$pattern
.
'suU'
,
$subject
,
$sets
,
PREG_SET_ORDER
);
preg_match_all
(
$pattern
.
'suU'
,
$subject
,
$sets
,
PREG_SET_ORDER
);
foreach
(
$sets
as
&
$set
)
foreach
(
$sets
as
&
$set
)
foreach
(
$set
as
$i
=>
$match
)
foreach
(
$set
as
$i
=>
$match
)
if
(
is_numeric
(
$i
)
/*&& $i != 0*/
)
if
(
is_numeric
(
$i
)
/*&& $i != 0*/
)
unset
(
$set
[
$i
]);
unset
(
$set
[
$i
]);
return
$sets
;
return
$sets
;
}
}
protected
function
fixSentence
(
$str
)
protected
function
fixSentence
(
$str
)
{
{
// TODO fix word wrap
// TODO fix word wrap
if
(
$str
==
''
)
if
(
$str
==
''
)
return
''
;
return
''
;
return
strtoupper
(
substr
(
$str
,
0
,
1
))
.
substr
(
$str
,
1
)
.
(
$str
[
strlen
(
$str
)
-
1
]
!=
'.'
?
'.'
:
''
);
return
strtoupper
(
substr
(
$str
,
0
,
1
))
.
substr
(
$str
,
1
)
.
(
$str
[
strlen
(
$str
)
-
1
]
!=
'.'
?
'.'
:
''
);
}
}
protected
function
getPropParam
(
$prop
,
$param
)
protected
function
getPropParam
(
$prop
,
$param
)
{
{
return
isset
(
$prop
[
'get'
])
?
$prop
[
'get'
][
$param
]
:
$prop
[
'set'
][
$param
];
return
isset
(
$prop
[
'get'
])
?
$prop
[
'get'
][
$param
]
:
$prop
[
'set'
][
$param
];
}
}
}
}
\ No newline at end of file
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