Showing 1,051 of 1,052 total issues
Method V030Handshaker.receiveRemoteStatus
has 8 return statements (exceeds 4 allowed). Open
func (h *V030Handshaker) receiveRemoteStatus(ctx context.Context) (*types.Status, error) {
// and wait to response status
data, err := h.msgRW.ReadMsg()
if err != nil {
h.sendGoAway("malformed message")
Method V200Handshaker.checkRemoteStatus
has 8 return statements (exceeds 4 allowed). Open
func (h *V200Handshaker) checkRemoteStatus(remotePeerStatus *types.Status) error {
// check if chainID is same or not
remoteChainID := types.NewChainID()
err := remoteChainID.Read(remotePeerStatus.ChainID)
if err != nil {
Method AergoRPCService.GetConfChangeProgress
has 8 return statements (exceeds 4 allowed). Open
func (rpc *AergoRPCService) GetConfChangeProgress(ctx context.Context, in *types.SingleBytes) (*types.ConfChangeProgress, error) {
var (
progress *types.ConfChangeProgress
err error
)
Method baseWireHandshaker.readWireHSRequest
has 8 return statements (exceeds 4 allowed). Open
func (h *baseWireHandshaker) readWireHSRequest(rd io.Reader) (header p2pcommon.HSHeadReq, err error) {
buf := make([]byte, p2pcommon.HSMagicLength)
readn, err := p2putil.ReadToLen(rd, buf[:p2pcommon.HSMagicLength])
if err != nil {
return
Method Cluster.validateChangeMembership
has 8 return statements (exceeds 4 allowed). Open
func (cl *Cluster) validateChangeMembership(cc *raftpb.ConfChange, member *consensus.Member, needlock bool) error {
if member == nil {
return ErrCCMemberIsNil
}
Method InboundWireHandshaker.handleInboundPeer
has 8 return statements (exceeds 4 allowed). Open
func (h *InboundWireHandshaker) handleInboundPeer(ctx context.Context, rwc io.ReadWriteCloser) (*p2pcommon.HandshakeResult, error) {
// wait initial hs message
hsReq, err := h.readWireHSRequest(rwc)
select {
case <-ctx.Done():
Method reorganizer.gather
has 8 return statements (exceeds 4 allowed). Open
func (reorg *reorganizer) gather() error {
//find branch root block , gather rollforward Target block
var err error
cdb := reorg.cs.cdb
Method Web3APIv1.ListEvents
has 8 return statements (exceeds 4 allowed). Open
func (api *Web3APIv1) ListEvents() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Function sendTX
has 8 return statements (exceeds 4 allowed). Open
func sendTX(cmd *cobra.Command, tx *types.Tx, account []byte) string {
if rootConfig.KeyStorePath != "" {
var err error
if pw == "" {
pw, err = getPasswd(cmd, false)
Function execVote
has 8 return statements (exceeds 4 allowed). Open
func execVote(cmd *cobra.Command, args []string) {
account, err := types.DecodeAddress(address)
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
return
Method blockExecutor.execute
has 8 return statements (exceeds 4 allowed). Open
func (e *blockExecutor) execute() error {
// Receipt must be committed unconditionally.
if !e.commitOnly {
defer contract.CloseDatabase()
logger.Trace().Int("txCount", len(e.txs)).Msg("executing txs")
Method PeerMapService.handleQuery
has 8 return statements (exceeds 4 allowed). Open
func (pms *PeerMapService) handleQuery(conn p2pcommon.RemoteConn, container p2pcommon.Message, query *types.MapQuery) (*types.MapResponse, error) {
if query.Status == nil {
return nil, fmt.Errorf("malformed query %v", query)
}
receivedMeta := p2pcommon.NewMetaFromStatus(query.Status)
Method ChainStateDB.SetGenesis
has 8 return statements (exceeds 4 allowed). Open
func (sdb *ChainStateDB) SetGenesis(genesis *types.Genesis, bpInit func(*statedb.StateDB, *types.Genesis) error) error {
block := genesis.Block()
stateDB := sdb.OpenNewStateDB(sdb.GetRoot())
// create state of genesis block
Method BlockFetcher.searchCandidateTask
has 8 return statements (exceeds 4 allowed). Open
func (bf *BlockFetcher) searchCandidateTask() (*FetchTask, error) {
getNewHashSet := func() (*HashSet, error) {
if bf.curHashSet == nil { //blocking
logger.Info().Msg("BlockFetcher waiting first hashset")
Function ValidateNameTx
has 8 return statements (exceeds 4 allowed). Open
func ValidateNameTx(tx *types.TxBody, sender *state.AccountState, scs *statedb.ContractState) (*types.CallInfo, error) {
if sender != nil && sender.Balance().Cmp(tx.GetAmountBigInt()) < 0 {
return nil, types.ErrInsufficientBalance
}
Method SQLiteConn.RegisterFunc
has 8 return statements (exceeds 4 allowed). Open
func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) error {
var fi functionInfo
fi.f = reflect.ValueOf(impl)
t := fi.f.Type()
if t.Kind() != reflect.Func {
Method transaction.ValidateWithSenderState
has 8 return statements (exceeds 4 allowed). Open
func (tx *transaction) ValidateWithSenderState(senderState *State, gasPrice *big.Int, version int32) error {
if (senderState.GetNonce() + 1) > tx.GetBody().GetNonce() {
return ErrTxNonceTooLow
}
amount := tx.GetBody().GetAmountBigInt()
Function Create
has 8 return statements (exceeds 4 allowed). Open
func Create(
contractState *statedb.ContractState,
code, contractAddress []byte,
ctx *vmContext,
) (string, []*types.Event, *big.Int, error) {
Function refreshAllVote
has 8 return statements (exceeds 4 allowed). Open
func refreshAllVote(context *SystemContext) error {
var (
scs = context.scs
account = context.Sender.ID()
staked = context.Staked
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else {
for i := start; i >= end; i-- {
foundBlock, futureErr := extractBlockFromFuture(rpc.hub.RequestFuture(message.ChainSvc,
&message.GetBlockByNo{BlockNo: i}, defaultActorTimeout, "rpc.(*AergoRPCService).ListBlockHeaders#2"))
if nil != futureErr {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 120.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76