Conditions | 1 |
Paths | 1 |
Total Lines | 431 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
749 | public function provideExceptionData() { |
||
750 | return [ |
||
751 | 'no entity id given' => [ |
||
752 | 'p' => [ 'data' => '{}' ], |
||
753 | 'e' => [ 'exception' => [ |
||
754 | 'type' => ApiUsageException::class, |
||
755 | 'code' => 'param-illegal' |
||
756 | ] ] ], |
||
757 | 'empty entity id given' => [ |
||
758 | 'p' => [ 'id' => '', 'data' => '{}' ], |
||
759 | 'e' => [ 'exception' => [ |
||
760 | 'type' => ApiUsageException::class, |
||
761 | 'code' => 'invalid-entity-id' |
||
762 | ] ] ], |
||
763 | 'invalid id' => [ |
||
764 | 'p' => [ 'id' => 'abcde', 'data' => '{}' ], |
||
765 | 'e' => [ 'exception' => [ |
||
766 | 'type' => ApiUsageException::class, |
||
767 | 'code' => 'invalid-entity-id' |
||
768 | ] ] ], |
||
769 | 'unknown id' => [ |
||
770 | 'p' => [ 'id' => 'Q1234567', 'data' => '{}' ], |
||
771 | 'e' => [ 'exception' => [ |
||
772 | 'type' => ApiUsageException::class, |
||
773 | 'code' => 'no-such-entity' |
||
774 | ] ] ], |
||
775 | 'invalid explicit id' => [ |
||
776 | 'p' => [ 'id' => '1234', 'data' => '{}' ], |
||
777 | 'e' => [ 'exception' => [ |
||
778 | 'type' => ApiUsageException::class, |
||
779 | 'code' => 'invalid-entity-id' |
||
780 | ] ] ], |
||
781 | 'non existent sitelink' => [ |
||
782 | 'p' => [ 'site' => 'dewiki','title' => 'NonExistent', 'data' => '{}' ], |
||
783 | 'e' => [ 'exception' => [ |
||
784 | 'type' => ApiUsageException::class, |
||
785 | 'code' => 'no-such-entity-link' |
||
786 | ] ] ], |
||
787 | 'missing site (also bad title)' => [ |
||
788 | 'p' => [ 'title' => 'abcde', 'data' => '{}' ], |
||
789 | 'e' => [ 'exception' => [ |
||
790 | 'type' => ApiUsageException::class, |
||
791 | 'code' => 'param-missing' |
||
792 | ] ] ], |
||
793 | 'missing site but id given' => [ |
||
794 | 'p' => [ 'title' => 'abcde', 'id' => 'Q12', 'data' => '{}' ], |
||
795 | 'e' => [ 'exception' => [ |
||
796 | 'type' => ApiUsageException::class, |
||
797 | 'code' => 'param-missing' |
||
798 | ] ] ], |
||
799 | 'cant have id and new' => [ |
||
800 | 'p' => [ 'id' => 'q666', 'new' => 'item', 'data' => '{}' ], |
||
801 | 'e' => [ 'exception' => [ |
||
802 | 'type' => ApiUsageException::class, |
||
803 | 'code' => 'param-illegal', |
||
804 | 'message' => 'Either provide the item "id" or pairs of "site" and "title" or a "new" type for an entity', |
||
805 | ] ] ], |
||
806 | 'when clearing must also have data!' => [ |
||
807 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin', 'clear' => '' ], |
||
808 | 'e' => [ 'exception' => [ |
||
809 | 'type' => ApiUsageException::class, |
||
810 | 'code' => $this->logicalOr( |
||
811 | $this->equalTo( 'nodata' ), |
||
812 | $this->equalTo( 'missingparam' ) |
||
813 | ) |
||
814 | ] ] ], |
||
815 | 'bad site' => [ |
||
816 | 'p' => [ 'site' => 'abcde', 'data' => '{}' ], |
||
817 | 'e' => [ 'exception' => [ |
||
818 | 'type' => ApiUsageException::class, |
||
819 | 'code' => $this->logicalOr( |
||
820 | $this->equalTo( 'unknown_site' ), |
||
821 | $this->equalTo( 'badvalue' ) |
||
822 | ) |
||
823 | ] ] ], |
||
824 | 'no data provided' => [ |
||
825 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin' ], |
||
826 | 'e' => [ 'exception' => [ |
||
827 | 'type' => ApiUsageException::class, |
||
828 | 'code' => $this->logicalOr( |
||
829 | $this->equalTo( 'nodata' ), // see 'no$1' in ApiBase::$messageMap |
||
830 | $this->equalTo( 'missingparam' ) |
||
831 | ) |
||
832 | ] ] |
||
833 | ], |
||
834 | 'malformed json' => [ |
||
835 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin', 'data' => '{{{}' ], |
||
836 | 'e' => [ 'exception' => [ |
||
837 | 'type' => ApiUsageException::class, |
||
838 | 'code' => 'invalid-json' |
||
839 | ] ] ], |
||
840 | 'must be a json object (json_decode s this an an int)' => [ |
||
841 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin', 'data' => '1234' ], |
||
842 | 'e' => [ 'exception' => [ |
||
843 | 'type' => ApiUsageException::class, |
||
844 | 'code' => 'not-recognized-array' |
||
845 | ] ] ], |
||
846 | 'must be a json object (json_decode s this an an indexed array)' => [ |
||
847 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin', 'data' => '[ "xyz" ]' ], |
||
848 | 'e' => [ 'exception' => [ |
||
849 | 'type' => ApiUsageException::class, |
||
850 | 'code' => 'not-recognized-string' |
||
851 | ] ] ], |
||
852 | 'must be a json object (json_decode s this an a string)' => [ |
||
853 | 'p' => [ 'site' => 'enwiki', 'title' => 'Berlin', 'data' => '"string"' ], |
||
854 | 'e' => [ 'exception' => [ |
||
855 | 'type' => ApiUsageException::class, |
||
856 | 'code' => 'not-recognized-array' |
||
857 | ] ] ], |
||
858 | 'inconsistent site in json' => [ |
||
859 | 'p' => [ |
||
860 | 'site' => 'enwiki', |
||
861 | 'title' => 'Berlin', |
||
862 | 'data' => '{"sitelinks":{"ptwiki":{"site":"svwiki","title":"TestPage!"}}}' |
||
863 | ], |
||
864 | 'e' => [ 'exception' => [ |
||
865 | 'type' => ApiUsageException::class, |
||
866 | 'code' => 'inconsistent-site' |
||
867 | ] ] ], |
||
868 | 'inconsistent lang in json' => [ |
||
869 | 'p' => [ |
||
870 | 'site' => 'enwiki', |
||
871 | 'title' => 'Berlin', |
||
872 | 'data' => '{"labels":{"de":{"language":"pt","value":"TestPage!"}}}' |
||
873 | ], |
||
874 | 'e' => [ 'exception' => [ |
||
875 | 'type' => ApiUsageException::class, |
||
876 | 'code' => 'inconsistent-language' |
||
877 | ] ] ], |
||
878 | 'inconsistent unknown site in json' => [ |
||
879 | 'p' => [ |
||
880 | 'site' => 'enwiki', |
||
881 | 'title' => 'Berlin', |
||
882 | 'data' => '{"sitelinks":{"BLUB":{"site":"BLUB","title":"TestPage!"}}}' |
||
883 | ], |
||
884 | 'e' => [ 'exception' => [ |
||
885 | 'type' => ApiUsageException::class, |
||
886 | 'code' => 'not-recognized-site' |
||
887 | ] ] ], |
||
888 | 'inconsistent unknown languages' => [ |
||
889 | 'p' => [ |
||
890 | 'site' => 'enwiki', |
||
891 | 'title' => 'Berlin', |
||
892 | 'data' => '{"labels":{"BLUB":{"language":"BLUB","value":"ImaLabel"}}}' |
||
893 | ], |
||
894 | 'e' => [ 'exception' => [ |
||
895 | 'type' => ApiUsageException::class, |
||
896 | 'code' => 'not-recognized-language' |
||
897 | ] ] ], |
||
898 | // @todo the error codes in the overly long string tests make no sense |
||
899 | // and should be corrected... |
||
900 | 'overly long label' => [ |
||
901 | 'p' => [ |
||
902 | 'site' => 'enwiki', |
||
903 | 'title' => 'Berlin', |
||
904 | 'data' => '{"labels":{"en":{"language":"en","value":"' |
||
905 | . TermTestHelper::makeOverlyLongString() . '"}}}' |
||
906 | ], |
||
907 | 'e' => [ 'exception' => [ 'type' => ApiUsageException::class ] ] ], |
||
908 | 'overly long description' => [ |
||
909 | 'p' => [ |
||
910 | 'site' => 'enwiki', |
||
911 | 'title' => 'Berlin', |
||
912 | 'data' => '{"descriptions":{"en":{"language":"en","value":"' |
||
913 | . TermTestHelper::makeOverlyLongString() . '"}}}' |
||
914 | ], |
||
915 | 'e' => [ 'exception' => [ 'type' => ApiUsageException::class ] ] ], |
||
916 | 'missing language in labels (T54731)' => [ |
||
917 | 'p' => [ |
||
918 | 'site' => 'enwiki', |
||
919 | 'title' => 'Berlin', |
||
920 | 'data' => '{"labels":{"de":{"site":"pt","title":"TestString"}}}' |
||
921 | ], |
||
922 | 'e' => [ 'exception' => [ |
||
923 | 'type' => ApiUsageException::class, |
||
924 | 'code' => 'missing-language', |
||
925 | 'message' => '\'language\' was not found in term serialization for de' |
||
926 | ] ] |
||
927 | ], |
||
928 | 'removing invalid claim fails' => [ |
||
929 | 'p' => [ |
||
930 | 'site' => 'enwiki', |
||
931 | 'title' => 'Berlin', |
||
932 | 'data' => '{"claims":[{"remove":""}]}' |
||
933 | ], |
||
934 | 'e' => [ 'exception' => [ |
||
935 | 'type' => ApiUsageException::class, |
||
936 | 'code' => 'invalid-claim', |
||
937 | 'message' => 'Cannot remove a claim with no GUID' |
||
938 | ] ] |
||
939 | ], |
||
940 | 'invalid entity ID in data value' => [ |
||
941 | 'p' => [ |
||
942 | 'id' => '%Berlin%', |
||
943 | 'data' => '{ "claims": [ { |
||
944 | "mainsnak": { "snaktype": "novalue", "property": "P0" }, |
||
945 | "type": "statement" |
||
946 | } ] }' |
||
947 | ], |
||
948 | 'e' => [ 'exception' => [ |
||
949 | 'type' => ApiUsageException::class, |
||
950 | 'code' => 'invalid-claim', |
||
951 | 'message' => '\'P0\' is not a valid' |
||
952 | ] ] |
||
953 | ], |
||
954 | 'invalid statement GUID' => [ |
||
955 | 'p' => [ |
||
956 | 'id' => '%Berlin%', |
||
957 | 'data' => '{ "claims": [ { |
||
958 | "id": "Q0$GUID", |
||
959 | "mainsnak": { "snaktype": "novalue", "property": "%P56%" }, |
||
960 | "type": "statement" |
||
961 | } ] }' |
||
962 | ], |
||
963 | 'e' => [ 'exception' => [ |
||
964 | 'type' => ApiUsageException::class, |
||
965 | 'code' => 'modification-failed', |
||
966 | 'message' => 'Statement GUID can not be parsed', |
||
967 | ] ] |
||
968 | ], |
||
969 | 'removing valid claim with no guid fails' => [ |
||
970 | 'p' => [ |
||
971 | 'site' => 'enwiki', |
||
972 | 'title' => 'Berlin', |
||
973 | 'data' => '{ |
||
974 | "claims": [ { |
||
975 | "remove": "", |
||
976 | "mainsnak": { |
||
977 | "snaktype": "value", |
||
978 | "property": "%P56%", |
||
979 | "datavalue": { "value": "imastring", "type": "string" } |
||
980 | }, |
||
981 | "type": "statement", |
||
982 | "rank": "normal" |
||
983 | } ] |
||
984 | }' |
||
985 | ], |
||
986 | 'e' => [ 'exception' => [ |
||
987 | 'type' => ApiUsageException::class, |
||
988 | 'code' => 'invalid-claim', |
||
989 | ] ] |
||
990 | ], |
||
991 | 'bad badge id' => [ |
||
992 | 'p' => [ |
||
993 | 'site' => 'enwiki', |
||
994 | 'title' => 'Berlin', |
||
995 | 'data' => '{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!",' |
||
996 | . '"badges":["abc","%Q149%"]}}}' |
||
997 | ], |
||
998 | 'e' => [ 'exception' => [ |
||
999 | 'type' => ApiUsageException::class, |
||
1000 | 'code' => 'invalid-entity-id' |
||
1001 | ] ] |
||
1002 | ], |
||
1003 | 'badge id is not an item id' => [ |
||
1004 | 'p' => [ |
||
1005 | 'site' => 'enwiki', |
||
1006 | 'title' => 'Berlin', |
||
1007 | 'data' => '{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!",' |
||
1008 | . '"badges":["P2","%Q149%"]}}}' |
||
1009 | ], |
||
1010 | 'e' => [ 'exception' => [ |
||
1011 | 'type' => ApiUsageException::class, |
||
1012 | 'code' => 'invalid-entity-id' |
||
1013 | ] ] |
||
1014 | ], |
||
1015 | 'badge id is not specified' => [ |
||
1016 | 'p' => [ |
||
1017 | 'site' => 'enwiki', |
||
1018 | 'title' => 'Berlin', |
||
1019 | 'data' => '{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!",' |
||
1020 | . '"badges":["%Q149%","%Q32%"]}}}' |
||
1021 | ], |
||
1022 | 'e' => [ 'exception' => [ |
||
1023 | 'type' => ApiUsageException::class, |
||
1024 | 'code' => 'not-badge' |
||
1025 | ] ] |
||
1026 | ], |
||
1027 | 'badge item does not exist' => [ |
||
1028 | 'p' => [ |
||
1029 | 'site' => 'enwiki', |
||
1030 | 'title' => 'Berlin', |
||
1031 | 'data' => '{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!",' |
||
1032 | . '"badges":["Q99999","%Q149%"]}}}' |
||
1033 | ], |
||
1034 | 'e' => [ 'exception' => [ |
||
1035 | 'type' => ApiUsageException::class, |
||
1036 | 'code' => 'no-such-entity' |
||
1037 | ] ] |
||
1038 | ], |
||
1039 | 'no sitelink - cannot change badges' => [ |
||
1040 | 'p' => [ |
||
1041 | 'site' => 'enwiki', |
||
1042 | 'title' => 'Berlin', |
||
1043 | 'data' => '{"sitelinks":{"svwiki":{"site":"svwiki",' |
||
1044 | . '"badges":["%Q42%","%Q149%"]}}}' |
||
1045 | ], |
||
1046 | 'e' => [ 'exception' => [ |
||
1047 | 'type' => ApiUsageException::class, |
||
1048 | 'code' => 'modification-failed', |
||
1049 | 'message' => wfMessage( 'wikibase-validator-no-such-sitelink', 'svwiki' )->inLanguage( 'en' )->text(), |
||
1050 | ] ] |
||
1051 | ], |
||
1052 | 'bad id in serialization' => [ |
||
1053 | 'p' => [ 'id' => '%Berlin%', 'data' => '{"id":"Q13244"}' ], |
||
1054 | 'e' => [ 'exception' => [ |
||
1055 | 'type' => ApiUsageException::class, |
||
1056 | 'code' => 'param-invalid', |
||
1057 | 'message' => 'Invalid field used in call: "id", must match id parameter' |
||
1058 | ] ] |
||
1059 | ], |
||
1060 | 'bad type in serialization' => [ |
||
1061 | 'p' => [ 'id' => '%Berlin%', 'data' => '{"id":"%Berlin%","type":"foobar"}' ], |
||
1062 | 'e' => [ 'exception' => [ |
||
1063 | 'type' => ApiUsageException::class, |
||
1064 | 'code' => 'param-invalid', |
||
1065 | 'message' => 'Invalid field used in call: "type", ' |
||
1066 | . 'must match type associated with id' |
||
1067 | ] ] |
||
1068 | ], |
||
1069 | 'bad main snak replacement' => [ |
||
1070 | 'p' => [ 'id' => '%Berlin%', 'data' => json_encode( [ |
||
1071 | 'claims' => [ |
||
1072 | [ |
||
1073 | 'id' => '%BerlinP56%', |
||
1074 | 'mainsnak' => [ |
||
1075 | 'snaktype' => 'value', |
||
1076 | 'property' => '%P72%', |
||
1077 | 'datavalue' => [ |
||
1078 | 'value' => 'anotherstring', |
||
1079 | 'type' => 'string' |
||
1080 | ], |
||
1081 | ], |
||
1082 | 'type' => 'statement', |
||
1083 | 'rank' => 'normal' ], |
||
1084 | ], |
||
1085 | ] ) ], |
||
1086 | 'e' => [ 'exception' => [ |
||
1087 | 'type' => ApiUsageException::class, |
||
1088 | 'code' => 'modification-failed', |
||
1089 | 'message' => 'uses property %P56%, can\'t change to %P72%' ] ] ], |
||
1090 | 'invalid main snak' => [ |
||
1091 | 'p' => [ 'id' => '%Berlin%', 'data' => json_encode( [ |
||
1092 | 'claims' => [ |
||
1093 | [ |
||
1094 | 'id' => '%BerlinP56%', |
||
1095 | 'mainsnak' => [ |
||
1096 | 'snaktype' => 'value', |
||
1097 | 'property' => '%P56%', |
||
1098 | 'datavalue' => [ 'value' => ' ', 'type' => 'string' ], |
||
1099 | ], |
||
1100 | 'type' => 'statement', |
||
1101 | 'rank' => 'normal' ], |
||
1102 | ], |
||
1103 | ] ) ], |
||
1104 | 'e' => [ 'exception' => [ |
||
1105 | 'type' => ApiUsageException::class, |
||
1106 | 'code' => 'modification-failed' ] ] ], |
||
1107 | 'properties cannot have sitelinks' => [ |
||
1108 | 'p' => [ |
||
1109 | 'id' => '%P56%', |
||
1110 | 'data' => '{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!"}}}', |
||
1111 | ], |
||
1112 | 'e' => [ 'exception' => [ |
||
1113 | 'type' => ApiUsageException::class, |
||
1114 | 'code' => 'not-supported', |
||
1115 | 'message' => 'The requested feature is not supported by the given entity' |
||
1116 | ] ] ], |
||
1117 | 'property with invalid datatype' => [ |
||
1118 | 'p' => [ |
||
1119 | 'new' => 'property', |
||
1120 | 'data' => '{"datatype":"invalid"}', |
||
1121 | ], |
||
1122 | 'e' => [ 'exception' => [ |
||
1123 | 'type' => ApiUsageException::class, |
||
1124 | 'code' => 'param-illegal' |
||
1125 | ] ] ], |
||
1126 | 'remove key misplaced in data' => [ |
||
1127 | 'p' => [ |
||
1128 | 'id' => '%Berlin%', |
||
1129 | 'data' => json_encode( [ |
||
1130 | 'remove' => '', |
||
1131 | 'claims' => [ [ |
||
1132 | 'type' => 'statement', |
||
1133 | 'mainsnak' => [ |
||
1134 | 'snaktype' => 'novalue', |
||
1135 | 'property' => '%P56%', |
||
1136 | ], |
||
1137 | 'id' => '%BerlinP56%', |
||
1138 | ] ], |
||
1139 | ] ) |
||
1140 | ], |
||
1141 | 'e' => [ 'exception' => [ |
||
1142 | 'type' => ApiUsageException::class, |
||
1143 | 'code' => 'not-recognized', |
||
1144 | 'message-key' => 'wikibase-api-illegal-entity-remove', |
||
1145 | ] ], |
||
1146 | ], |
||
1147 | 'invalid tag (one)' => [ |
||
1148 | 'p' => [ |
||
1149 | 'new' => 'item', |
||
1150 | 'data' => '{}', |
||
1151 | 'tags' => 'test tag that definitely does not exist', |
||
1152 | ], |
||
1153 | 'e' => [ 'exception' => [ |
||
1154 | 'type' => ApiUsageException::class, |
||
1155 | 'code' => $this->logicalOr( |
||
1156 | $this->equalTo( 'tags-apply-not-allowed-one' ), |
||
1157 | $this->equalTo( 'badtags' ) |
||
1158 | ), |
||
1159 | ] ], |
||
1160 | ], |
||
1161 | 'invalid tag (multi)' => [ |
||
1162 | 'p' => [ |
||
1163 | 'new' => 'item', |
||
1164 | 'data' => '{}', |
||
1165 | 'tags' => implode( '|', [ |
||
1166 | 'test tag that definitely does not exist', |
||
1167 | 'second test that that does not exist either', |
||
1168 | ] ), |
||
1169 | ], |
||
1170 | 'e' => [ 'exception' => [ |
||
1171 | 'type' => ApiUsageException::class, |
||
1172 | 'code' => $this->logicalOr( |
||
1173 | $this->equalTo( 'tags-apply-not-allowed-multi' ), |
||
1174 | $this->equalTo( 'badtags' ) |
||
1175 | ), |
||
1176 | ] ], |
||
1177 | ], |
||
1178 | ]; |
||
1179 | } |
||
1180 | |||
1309 |